I have a macro that successfully does a VLOOKUP on a sheet within the same workbook. I would now like to do the same thing but do the VLOOKUP on a sheet in a different workbook. I have done a lot of searching and reading but I cannot seem to get code that has no errors and works. Below is code that is working on a sheet in the same workbook. I would like to do it without having to open the second workbook.
I tried the following but I keep getting Runtime Error code 9.
I would appreciate any advice you can give me.
Thanks Doug
VBA Code:
Text_Last_Name.Value = Application.WorksheetFunction.Proper(Text_Last_Name.Value)
Dim LName As String
LName = Text_Last_Name.Value
On Error GoTo Skip
Text_First_Name.Text = Application.WorksheetFunction.VLookup(LName, ThisWorkbook.Sheets("Recuring Emails").Range("A2:G23").Value, 2, False)
Text_Address.Text = Application.WorksheetFunction.VLookup(LName, ThisWorkbook.Sheets("Recuring Emails").Range("A2:G23").Value, 3, False)
Text_City.Text = Application.WorksheetFunction.VLookup(LName, ThisWorkbook.Sheets("Recuring Emails").Range("A2:G23").Value, 4, False)
Text_State.Text = Application.WorksheetFunction.VLookup(LName, ThisWorkbook.Sheets("Recuring Emails").Range("A2:G23").Value, 5, False)
Text_Zip.Text = Application.WorksheetFunction.VLookup(LName, ThisWorkbook.Sheets("Recuring Emails").Range("A2:G23").Value, 6, False)
Text_Email.Text = Application.WorksheetFunction.VLookup(LName, ThisWorkbook.Sheets("Recuring Emails").Range("A2:G23").Value, 7, False)
ComboBox_Donation_Type = "Recurring"
I tried the following but I keep getting Runtime Error code 9.
VBA Code:
Dim Table2 As Range
Set Table2 = Workbooks("C:\Users\Doug\Desktop\KAH Test Data\KAH Main Update Sheet-10-1-21.xlsm").Sheets("Recuring Emails").Columns("A:G")
On Error GoTo Skip
fname = Application.WorksheetFunction.VLookup(lname, Table2, 2, False)
MsgBox ("First Name = " & fname)
I would appreciate any advice you can give me.
Thanks Doug