How to do Vlookup when range is dynamic

siddo

Board Regular
Joined
May 26, 2020
Messages
106
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have 2 tabs in an excel sheet and I have stored the last row of the column in LR1 variable I now want vlookup to perform the action everytime and take the range from "A1" TO "ALR1"
VBA Code:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],ProblemID_afterDupl!R2C1:R46C2,2,0)"
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I have 2 tabs in an excel sheet and I have stored the last row of the column in LR1 variable I now want vlookup to perform the action everytime and take the range from "A1" TO "ALR1"
VBA Code:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],ProblemID_afterDupl!R2C1:R46C2,2,0)"
VBA Code:
ActiveCell.FormulaR1C1 = "=VLOOKUP(A1,ProblemID_afterDupl!$A$2:$B$" & LR1 & ",2,0)"

Tried doing this however unable to run it
 
Upvote 0
VBA Code:
Range("B1").Select

Set prob = ThisWorkbook.Worksheets("ProblemID_afterDupl")
Set rand = ThisWorkbook.Worksheets("Random Transpose")


Set dataRng = prob.Range("A2:B" & LR1)

For y = 1 To Sample

rand.Range("B" & y).Value = Application.WorksheetFunction.VLookup( _
    rand.Range("A" & y).Value, dataRng, 2, False)
   
Next y

Where LR1 has the value of last row from my sheet1 & Sample has the value of last row from sheet2
 
Upvote 0
Solution

Forum statistics

Threads
1,216,000
Messages
6,128,204
Members
449,435
Latest member
Jahmia0616

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