vlookup VBA not working!!!

bran8989

New Member
Joined
Sep 14, 2018
Messages
23
Not sure what the issue is.. hopefully someone can help!!!

Heres my code:

Sub Test()

Dim SeriesName As Range
Dim LookupRange As Range
NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count

For x = 2 To NumRows
Set SeriesName = Series3.Range("A" & x).Value
Set LookupRange = CMBs.Range("A:C").Value
Range("C1").Select
shtInput.Range("C" & x).Value = Application.WorksheetFunction.VLookup(SeriesName, LookupRange, 2, False)


ActiveCell.Offset(1, 0).Select
Next


End Sub

Thanks!!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
.
I believe you need to Dim X As Integer.

Not certain that will totally correct your macro.

Can you explain in clear language how your worksheet is laid out and what you expect the macro to do with the data ?
A best practice would be to post your example workbook to DROPBOX or other cloud website for download so it can be
examined.
 
Upvote 0
How about
Code:
Sub Test()

Dim SeriesName As Range
Dim LookupRange As Range
numRows = Range("A1", Range("A1").End(xlDown)).Rows.count
Set LookupRange = CMBs.Range("A:C")

For x = 2 To numRows
   Set SeriesName = Series3.Range("A" & x)
   ShtInput.Range("C" & x).Value = Application.vlookup(SeriesName.Value, LookupRange, 2, False)
Next


End Sub
 
Upvote 0
Which line of code gave that error?
 
Upvote 0
Looks like its here...

Set LookupRange = CMBs.Range("A:C")


For x = 2 To numRows
Set SeriesName = Series3.Range("A" & x)
ShtInput.Range("C" & x).Value = Application.VLookup(SeriesName.Value, LookupRange, 2, False)
 
Upvote 0
Do you have a variable called CBs, or a sheet with that codename?
 
Upvote 0
I've got this now..

Sub Test1()


Dim SeriesName As Range
Dim LookupRange As Range
Dim Reference As Range


numRows = Range("A1", Range("A1").End(xlDown)).Rows.Count




For x = 2 To numRows
Set SeriesName = Sheet1.Range("A" & x)
Set LookupRange = Reference.Range("A:C")
Sheet3.Range("C" & x).Value = Application.VLookup(SeriesName, LookupRange, 2, False)
Next




End Sub


But it still gives me an "object variable or with block variable not set"..
 
Upvote 0
As the lookupRange never changes you should put that before the loop, otherwise it's constantly being reset every iteration.
What is "Reference" meant to be? you have declared it as a Range, but never assigned a value to it.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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