我是一个优秀的新手。我正在尝试编写宏来填充基于第一张工作表的sheet2。我在sheet1上有以下列: Name CustomName CustomeValue a Bay 11 a Site UK a Rack 3 b Site UK b Rack 2 C empty
表2-输出应如下名称Bay Site Rack a 11 UK 3 b UK 2 c
我确实尝试过编写宏来逐行匹配,并有选择地进行比较和填充,但脚本在大数据到来时会随机填充,在这方面的任何帮助都将不胜感激。
代码片段:
Sub populatingsheet2()
x = 2
y = 2
Sheet2.Cells(y, 1) = Sheet1.Cells(x, 1)
Do While x <= 4
If Sheet1.Cells(x, 1) = Sheet1.Cells(x + 1, 1) Then
‘I want unique records
'MsgBox "Identical"
If Sheet1.Cells(x, 2) = "Bay" Then
Sheet2.Cells(y, 2) = Sheet1.Cells(x, 3)
End If
If Sheet1.Cells(x, 2) = "Site" Then
Sheet2.Cells(y, 3) = Sheet1.Cells(x, 3)
End If
If Sheet1.Cells(x, 2) = "Rack" Then
Sheet2.Cells(y, 4) = Sheet1.Cells(x, 3)
End If
Else: 'MsgBox "Not Identical"
End If
x = x + 1
y = y + 1
Loop
End Sub发布于 2013-04-09 19:38:02
那么,你有没有考虑过,你可以在没有宏的情况下,使用表2上的公式来完成所有这些工作?
可能类似于表2中的列B:
=IF(Sheet1!B:B="Bay",Sheet1!C:C,"")在C栏
=IF(Sheet1!B:B="Site",SHeet1!C:C,"")hth
菲利普
https://stackoverflow.com/questions/15898117
复制相似问题