Philip1957
Board Regular
- Joined
- Sep 30, 2014
- Messages
- 185
- Office Version
- 365
- Platform
- Windows
Greetings,
I'm trying to set up a macro that is beyond my current skill level with VBA and I'm struggling.
I have two workbooks ("IP_Master" and "IP Lookup") and I need to look up information in one to transfer it to the other. The number of rows in the ranges involved in both workbooks can change from week to week.
I have defined the two workbooks as variables and Named the data range in each.
I can get the Vlookup to run once with this:
I'm having a heck of a time getting it to loop through the entire range though. Here's the most recent of multiple failed attempts.
This hangs at the"lrow=" statement. I'm hoping someone can educate me on what I'm doing wrong here.
I also don't understand why this works:
But this doesn't, even though I've defined the variable wb4 as the workbook "IP_Master"
Thanks in advance for any assistance.
I know that time is valuable and appreciate you spending some on my problem.
~ Phil
I'm trying to set up a macro that is beyond my current skill level with VBA and I'm struggling.
I have two workbooks ("IP_Master" and "IP Lookup") and I need to look up information in one to transfer it to the other. The number of rows in the ranges involved in both workbooks can change from week to week.
I have defined the two workbooks as variables and Named the data range in each.
I can get the Vlookup to run once with this:
VBA Code:
Private Sub IP_Vlook_Master_to_Lookup()
'Lookup the IP address in IP Master, copy to IP Lookup
Dim wb1 As Workbook
Set wb1 = ThisWorkbook
Dim wb3 As Workbook
Set wb3 = Workbooks("IP Lookup.xlsx")
Dim wb4 As Workbook
Set wb4 = Workbooks("IP_Master.xlsx")
wb3.Activate
Range("B2").Select
ActiveCell = "=VLOOKUP(A2,IP_Master.xlsx!IPM_tbl,2,0)"
End Sub
I'm having a heck of a time getting it to loop through the entire range though. Here's the most recent of multiple failed attempts.
VBA Code:
Private Sub IP_Vlook_Master_to_Lookup()
'Lookup the IP address in IP Master, copy to IP Lookup
Dim wb1 As Workbook
Set wb1 = ThisWorkbook
Dim wb3 As Workbook
Set wb3 = Workbooks("IP Lookup.xlsx")
Dim wb4 As Workbook
Set wb4 = Workbooks("IP_Master.xlsx")
Dim i As Integer
Dim lrow As Integer
lrow = Workbooks("IP Lookup.xlsx!IPL_tbl")(Rows.Count, "A").End(xlUp).Row
wb3.Activate
For i = 2 To lrow
Range("B2").Select
'ActiveCell.Value = Application.WorksheetFunction.VLookup(Range("B2" & i), 2, 0)
Next i
End Sub
This hangs at the"lrow=" statement. I'm hoping someone can educate me on what I'm doing wrong here.
I also don't understand why this works:
VBA Code:
ActiveCell = "=VLOOKUP(A2,IP_Master.xlsx!IPM_tbl,2,0)"
But this doesn't, even though I've defined the variable wb4 as the workbook "IP_Master"
VBA Code:
ActiveCell = "=VLOOKUP(A2,wb4!IPM_tbl,2,0)"
Thanks in advance for any assistance.
I know that time is valuable and appreciate you spending some on my problem.
~ Phil