VBA to loop through table & lookup value from another table

deterding

New Member
Joined
Sep 16, 2015
Messages
8
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
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top