Getting an error when doing a VLOOKUP

2quik4u2

New Member
Joined
Aug 16, 2011
Messages
1
Hi I am running the following code, trying to check and see if values in a cell have changed everytime the sub runs (through a button on the worksheet. Essentially I am looking up data in another closed excel file called "TODAY" comparing it to data in the new workbook and if there is any difference updating the values. but I am getting an "Runtime error: 9 subscript out of range" error. Can anyone help me?

Sub UpdateWorksheet()
Range("C3").Copy
Range("D3").PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Dim tp As Integer
Dim risk As String
Dim rating As String
Dim drequested As Range
Dim row As Integer
Dim ddate As String
Dim rng As Range

For row = 5 To 119
tp = Application.WorksheetFunction.VLookup(Cells(row, 2).Value, Workbooks("TODAY.xls").Worksheets(1).Range("$D$2:$Y$307"), 10, False)

risk = Application.WorksheetFunction.VLookup(Cells(row, 2).Value, Workbooks("TODAY.xls").Worksheets(1).Range("$D$2:$Y$307"), 21, False)
rating = Application.WorksheetFunction.VLookup(Cells(row, 2).Value, Workbooks("TODAY.xls").Worksheets(1).Range("$D$2:$Y$307"), 20, False)


If Cells(row, 4) <> tp Or Cells(row, 5) <> rating Or Cells(row, 8) <> risk Then

Cells(row, 8) = Application.WorksheetFunction.VLookup(Cells(row, 2).Value, Workbooks("TODAY.xls").Worksheets(1).Range("$D$2:$Y$307"), 1, False)
Cells(row, 5) = Application.WorksheetFunction.VLookup(Cells(row, 2).Value, Workbooks("TODAY.xls").Worksheets(1).Range("$D$2:$Y$307"), 20, False)
Cells(row, 4) = Application.WorksheetFunction.VLookup(Cells(row, 2).Value, Workbooks("TODAY.xls").Worksheets(1).Range("$D$2:$Y$307"), 10, False)
Cells(row, 6) = ddate

End If

Next row

End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
this error usually occurs when the data is to large for the variable to handle.

maybe start by changing the integers to long
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,668
Members
449,463
Latest member
Jojomen56

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