我有兩張表單,一個名爲bill,另一個名爲sheet1。如果名稱與表單1中的表單2不匹配,則將名稱添加到表單2
我有VBA代碼來查找名稱並將信息粘貼到匹配的名稱,但是如何添加一個不存在的新名稱?
然後如果找不到名稱,添加名字賬單F列列192和F列列193
例如:
票據
A B C D E F G H
xxx xxxx xxx xxx xx bill xxx
xxx xxxx xxx xxx xx bill xxx
xxx xxxx xxx xxx xx man xxx
xxx xxxx xxx xxx xx man xxx
sheet1
A B
bill 19.23
man 156.23
這裏是我到目前爲止:
Dim sh1 As Worksheet, sh2 As Worksheet
Dim j As Long, i As Long, lastrow As Long
Set sh1 = Worksheets("test")
Set sh2 = Worksheets("Sheet1")
lastrow1 = sh1.Cells(Rows.Count, "F").End(xlUp).Row
lastrow2 = sh2.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow1
For j = 1 To lastrow2
If sh1.Cells(i, "F").Value = sh2.Cells(j, "A").Value Then
sh1.Cells(i, "H").Value = sh2.Cells(j, "B").Value
End If
Next j
Next i
End Sub
您是否在製作數據透視表? Excel的數據透視表功能可以在不使用宏的情況下解決您的問題嗎? –
我需要一個宏,因爲我在C程序中運行其他宏。# – user1013478
您可以將數據透視表合併到宏中。在我看來,這是這裏阻力最小的路徑。 – Pynner