【问题标题】:VBA code required需要 VBA 代码
【发布时间】:2016-01-07 07:18:18
【问题描述】:

比较不同工作表中的两个单元格需要 VBA 代码,如果匹配,则将第一个工作表数据水平复制到第二个工作表(在匹配的单元格前面)

如表 1 所示

Date                Party Name            Amount
23-12-15            Adani                 150000
                    Shree cement          200000
                    Jindal                100000
                    Mittal                50000

在第 2 页中

01-12-15
05-12-15
10-12-15
20-12-15
23-12-15

如果工作表 2 的数据与工作表 1(日期)匹配

需要输出

01-12-15
05-12-15
10-12-15
20-12-15
23-12-15  Adani 150000  shree cement 200000  Jindal 100000 Mittal 50000

【问题讨论】:

  • excel中的数据是不是和上面的一模一样?每个日期可以有多少个派对名称?

标签: vba excel compare


【解决方案1】:

此代码将检查不同工作表中的列并将它们放在第三个工作表中。你可以修改它来做你需要的:

dim idx1 as integer
dim idx2 as integer
dim idx3 as integer
idx1 = 2
idx3 = 1
while sheets("Sheet1").Range("A" + Cstr(idx1)).Value <> "" 
    idx2 = 2
    while sheets("Sheet2").Range("B" + Cstr(idx2)).Value <> ""
        if sheets("Sheet1").Range("A" + Cstr(idx1)).Value = sheets("Sheet2").Range("B" + Cstr(idx2)).Value then
            idx3 = idx3 + 1
            sheets("Sheet3").Range("C" + Cstr(idx3)).value = sheets("Sheet1").Range("A" + Cstr(idx1)).Value
        endif
        idx2 = idx2 + 1
    wend
    idx1 = idx1 + 1
wend

【讨论】:

  • 显示您的代码。您需要修改我的代码以满足您的需求。如果我们看到您的代码,我们或许能够找出问题所在。
猜你喜欢
  • 1970-01-01
  • 2023-01-28
  • 1970-01-01
  • 2010-09-25
  • 1970-01-01
  • 1970-01-01
  • 2018-02-19
  • 2019-03-17
  • 1970-01-01
相关资源
最近更新 更多