Vlookup only using first lookup value when resizing formula

billyheanue

Board Regular
Joined
Jul 13, 2015
Messages
109
Hi Everyone,
I have rownum and colnum set to a value -- these are row and column coordinates for the FIRST lookup value. However, when I resize the formula to do the next value (which would have coords [rownum +1, colnum], the formula is still doing the vlookup with the same lookup value.

Does anyone know how to incorporate the lookup value's row number increasing by 1 each time, when the formula is resized?

Thank you everyone!

Code:
Private Sub CommandButton8_Click()
Dim rownum As Long
Dim colnum As Long
Dim x As Long
Dim y As Long
Dim colindexval As Double
Dim resizeval As Double
Dim fVLOOKUP As String




rownum = Sheet1.Cells(28, 21).Value
colnum = Sheet1.Cells(27, 21).Value
x = Sheet1.Cells(20, 21).Value
y = Sheet1.Cells(21, 21).Value
resizeval = Sheet1.Cells(19, 12).Value
colindexval = Sheet1.Cells(29, 12).Value


fVLOOKUP = "=VLOOKUP(@1,'@2'!@3,@4,FALSE)"


fVLOOKUP = Replace(fVLOOKUP, "@1", Sheet9.Cells(rownum, colnum).Value)
fVLOOKUP = Replace(fVLOOKUP, "@2", Sheets("Price Data").Name)
fVLOOKUP = Replace(fVLOOKUP, "@3", Sheets("Price Data").Range("A12").CurrentRegion.Address)
fVLOOKUP = Replace(fVLOOKUP, "@4", colindexval)


Sheet9.Cells(y, x).Resize(resizeval, 1).Formula = fVLOOKUP


    
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
See if this works

Instead of this code line
Code:
fVLOOKUP = Replace(fVLOOKUP, "@1", Sheet9.Cells(rownum, colnum).Value)

try
Code:
fVLOOKUP = Replace(fVLOOKUP, "@1", Sheet9.Cells(rownum, colnum).Address(False, True))

Hope this helps

M.
 
Upvote 0
One more thing Marcelo,

Do you know how to make the new range (resizeval, 1) the active cells? I am trying to set it as the current selection and then have the formats pasted from the column to the left of it
 
Upvote 0
I tried
Code:
fVLOOKUP = "=VLOOKUP(@1,'@2'!@3,@4,FALSE)"


fVLOOKUP = Replace(fVLOOKUP, "@1", Sheet9.Cells(rownum, colnum).Address(False, True))
fVLOOKUP = Replace(fVLOOKUP, "@2", Sheets("Price Data").Name)
fVLOOKUP = Replace(fVLOOKUP, "@3", Sheets("Price Data").Range("A12").CurrentRegion.Address)
fVLOOKUP = Replace(fVLOOKUP, "@4", colindexval)


Sheet9.Cells(y, x).Resize(resizeval, 1).Formula = fVLOOKUP
Range(Sheet9.Cells(y, x), (Sheet9.Cells(y, x).End(xlDown))).Select

and got err1004: Method 'Range' of object'_Worksheet' failed
 
Upvote 0
Before

Range(Sheet9.Cells(y, x), (Sheet9.Cells(y, x).End(xlDown))).Select

M.
 
Upvote 0

Forum statistics

Threads
1,215,307
Messages
6,124,168
Members
449,146
Latest member
el_gazar

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