I have a master sheet "Penalties" that I need to update with monthly data. I need to do a lookup without writing formulas on the sheet. The data sheet "November1" has only a portion of the data that applies to the Month of November. More data will come in weekly.
The "November1" (data) sheet has 2,459 rows (this number will vary). Row 1 is a header, data starts at row 2. Column K has the data (number) to retrieve. Column J has the lookup key (number).
The Penalties (master) sheet has 25,923 rows (may vary some). There are headers and data starts at row 7. Column BW has the lookup key (number).
In this case if I use Vlookup or Index Match I would have to loop through the master sheet which I think will take along time due to the size of the sheet. I was trying to use Index Match to see just how long but I am doing something wrong. I haven't found a good example through Google. I tried a routine with Autofilter and looping through the data sheet, way to slow at 3 hrs 20 min in this case. Then I tried another routine with Find looping through the data sheet, much better at 22.5 min. Is there a better way? If not I'll stick with my Find routine. Thanks.
renigar
With this code I get "Unable to get the Match property of the WorksheetFunction class", Run-time error 1004.
The "November1" (data) sheet has 2,459 rows (this number will vary). Row 1 is a header, data starts at row 2. Column K has the data (number) to retrieve. Column J has the lookup key (number).
The Penalties (master) sheet has 25,923 rows (may vary some). There are headers and data starts at row 7. Column BW has the lookup key (number).
In this case if I use Vlookup or Index Match I would have to loop through the master sheet which I think will take along time due to the size of the sheet. I was trying to use Index Match to see just how long but I am doing something wrong. I haven't found a good example through Google. I tried a routine with Autofilter and looping through the data sheet, way to slow at 3 hrs 20 min in this case. Then I tried another routine with Find looping through the data sheet, much better at 22.5 min. Is there a better way? If not I'll stick with my Find routine. Thanks.
renigar
With this code I get "Unable to get the Match property of the WorksheetFunction class", Run-time error 1004.
Code:
Option Explicit
Sub TestLookup()
Dim ConsValue As Long
Dim i As Long
Dim dLastRow As Long
Dim pLastRow As Long
' Get the number of the last row of the data import sheet
dLastRow = Sheets("November1").Cells(Rows.Count, 1).End(xlUp).Row
' Get the number of the last row of the Penalties sheet
pLastRow = Sheets("Penalties").Cells(Rows.Count, 1).End(xlUp).Row
' Loop through the data import sheet to get consumption values
For i = 2 To pLastRow
'Lookup the consumption value on the November1 sheet
ConsValue = WorksheetFunction.Index(Sheets("November1").Range("K2:K" & dLastRow), _
WorksheetFunction.Match(Sheets("Penalties").Cells(i, 75), Sheets("November1").Range("J2:J" & dLastRow), 0))
MsgBox "Consumption = " & ConsValue & " Units"
' Continue loop
Next i
End Sub