[英]Excel: Compare 2 columns and pull missing data into 3rd column
一直在瘋狂搜索,但找不到我要找的東西。
A欄:部分員工(部分名單)
E欄:所有員工(完整列表)
我需要用不在 A 列中的所有其他員工填充 C 列(與 E 列相比,A 列將數據拉入不在 A 列中的 C 列)。
我已經嘗試過 IF、VLOOKUP 函數並且已經接近但不想在 C 列中出現任何空白單元格。
我更喜歡 VBA 代碼(因為 A 列和 C 列鏈接到外部數據源)並使用 VBA 填充。
提前致謝!
嘗試這個:
Sub test()
Dim LastRowA As Long
Dim LastRowC As Long
Dim LastRowE As Long
Dim i As Long
Dim j As Long
Dim NameNotExist As Boolean
LastRowA =Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row
LastRowC = Sheet1.Cells(Sheet1.Rows.Count, "C").End(xlUp).Row
LastRowE = Sheet1.Cells(Sheet1.Rows.Count, "E").End(xlUp).Row
For i = 1 To LastRowE
For j = 1 To LastRowA
NameNotExist = False
If Sheet1.Range("E" & i).Value =Sheet1.Range("A" & j).Value Then
Exit For
Else
NameNotExist = True
End If
Next j
If NameNotExist = True Then
If LastRowC = 1 And Sheet1.Range("C1").Value = "" Then
Sheet1.Range("C1").Value =Sheet1.Range("E" & i).Value
Else:
LastRowC =Sheet1.Cells(Sheet1.Rows.Count, "C").End(xlUp).Row
Sheet1.Range("C" & LastRowC + 1).Value = Sheet1.Range("E" & i).Value
End If
End If
Next i
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.