我是一个excel新手。我正在尝试编写宏以根据第一张填充 sheet2。我在 sheet1 上有以下列: Name CustomName CustomeValue a Bay 11 a Site UK a Rack 3 b Site UK b Rack 2 C empty empty
表 2 - 输出应如下所示 Name 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