Hello,
I have 2 tables:
Table 1 = Original names & phone numbers
Table 2 = New names & phone numbers
I want to loop through each of the phone numbers in the original Table & ONLY if the number is 0 or empty, lookup the new value from Table 2. I've started with the below. Sorry, I'm a novice. This must be done in VBA because I have over 40,000 lines to loop through & have to execute across multiple columns. Tried to use the Dictionary but it is beyond me.
Thanks
Sub test()
Dim tbl1 As ListObject
Dim a As Range
Dim b As Range
Dim tbl2 As ListObject
Dim c As Range
Dim d As Range
Set tbl1 = Sheet1.ListObjects("Original")
Set a = Sheet1.Range("Original[Name")
Set b = Sheet1.Range("Original[Number]")
Set tbl2 = Sheet2.ListObjects("New")
Set c = Sheet2.Range("New[Name]")
Set d = Sheet2.Range("New[Number]")
For Each cell In b
If cell.Value = 0 Or cell.Value = "none" Or IsEmpty(cell.Value) Then
cell.Value = Application.worksheetfFunction.Index(d, Application.worksheetfFunction.Match(a, c, 0), 1)
End If
Next
End Sub
I have 2 tables:
Table 1 = Original names & phone numbers
Table 2 = New names & phone numbers
I want to loop through each of the phone numbers in the original Table & ONLY if the number is 0 or empty, lookup the new value from Table 2. I've started with the below. Sorry, I'm a novice. This must be done in VBA because I have over 40,000 lines to loop through & have to execute across multiple columns. Tried to use the Dictionary but it is beyond me.
Thanks
Sub test()
Dim tbl1 As ListObject
Dim a As Range
Dim b As Range
Dim tbl2 As ListObject
Dim c As Range
Dim d As Range
Set tbl1 = Sheet1.ListObjects("Original")
Set a = Sheet1.Range("Original[Name")
Set b = Sheet1.Range("Original[Number]")
Set tbl2 = Sheet2.ListObjects("New")
Set c = Sheet2.Range("New[Name]")
Set d = Sheet2.Range("New[Number]")
For Each cell In b
If cell.Value = 0 Or cell.Value = "none" Or IsEmpty(cell.Value) Then
cell.Value = Application.worksheetfFunction.Index(d, Application.worksheetfFunction.Match(a, c, 0), 1)
End If
Next
End Sub