This is a follow-up post to an earlier post. This issue is resolved due to some great advice that was offered.
I'm helping a local animal shelter by developing a script to combine data from four worksheets into an overall report. All four sheets contain a common variable, which I've named AnimalID. AnimalID is located in column A on the Rabies Renewal and Rabies Jurisdiction sheets and is sorted from min to max. My previous question required locating the AnimalID on the Rabies Renewal sheet and using VLookup to copy an expiration date on the Report sheet. For reference, the dates are populated at the start of the report, at cell Q8 to bottom. I am trying to use (or so I think) the same approach to populate owner information on the Report sheet by finding the AnimalID on the Rabies Jurisdiction sheet. The owner information should be populated starting around cell A140 (previous cells are already populated), hence why I include two variables to mark position. When I attempt to run the script, I receive the following error when it reaches any of the commented VLookup lines.
Error: "Method 'VLookup' of object 'WorksheetFunction' failed"
I'm not sure if the A## value will populate properly but I think the others should work just fine. Thoughts and suggestions would be appreciated. Thanks!
Dim Ct As Long, lMaxRows As Long
Dim AnimalID As Range, Jurisdiction As Range, Renewal As Range
Worksheets("Rabies Renewal").Activate
Range("A:A").NumberFormat = "@"
Set Renewal = Sheets("Rabies Renewal").Range("A:K")
Worksheets("Rabies Jurisdiction").Activate
Range("A:AI").NumberFormat = "@"
Set Jurisdiction = Sheets("Rabies Jurisdiction").Range("A:AI")
Worksheets("Report").Activate
Range("Q:Q").NumberFormat = "@"
'Backfill owner information based on animal ID
lMaxRows = Cells(Rows.Count, "I").End(xlUp).Row
Range("L" & lMaxRows + 1).Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Ct = Selection.Count
For Ct = 1 To Ct
Set AnimalID = Range("Q" & Ct + lMaxRows)
'Range("A" & Ct + lMaxRows).Select
'ActiveCell.Value = WorksheetFunction.VLookup(AnimalID, Jurisdiction, 19 & ", " & 18, False)
'Range("C" & Ct + lMaxRows).Select
'ActiveCell.Value = WorksheetFunction.VLookup(AnimalID, Jurisdiction, 27, False)
'Range("E" & Ct + lMaxRows).Select
'ActiveCell.Value = WorksheetFunction.VLookup(AnimalID, Jurisdiction, 32, False)
'Range("F" & Ct + lMaxRows).Select
'ActiveCell.Value = WorksheetFunction.VLookup(AnimalID, Jurisdiction, 33, False)
'Range("G" & Ct + lMaxRows).Select
'ActiveCell.Value = WorksheetFunction.VLookup(AnimalID, Jurisdiction, 34, False)
'Range("I" & Ct + lMaxRows).Select
'ActiveCell.Value = WorksheetFunction.VLookup(AnimalID, Jurisdiction, 16, False)
'Range("J" & Ct + lMaxRows).Select
'ActiveCell.Value = WorksheetFunction.VLookup(AnimalID, Jurisdiction, 8, False)
'Range("K" & Ct + lMaxRows).Select
'ActiveCell.Value = WorksheetFunction.VLookup(AnimalID, Jurisdiction, 11, False)
On Error Resume Next
Next Ct
'Backfill rabies due dates based on animal ID
Range("Q8").Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Ct = Selection.Count
For Ct = 1 To Ct
Set AnimalID = Range("Q" & Ct + 7)
Range("P" & Ct + 7).Select
ActiveCell.Value = WorksheetFunction.VLookup(AnimalID, Renewal, 11, False)
On Error Resume Next
Next Ct
MsgBox "Completed"