Hi
I am trying to write a code with vlookup. The purpose of the code is to reference a data set in another sheet using vlookup and show the corresponding values. The data sets may may be varying in sizes. So i want the vlookup to go to the last cell possible with the data.
I have tried these two ways of calling vlookup, but nothing seems to work.
1.
2.
In sheet 2 range can change depending on the data set. that is what i want to be flexible. The autofill range also needs to be flexible, which i am unable to do.
I am trying to write a code with vlookup. The purpose of the code is to reference a data set in another sheet using vlookup and show the corresponding values. The data sets may may be varying in sizes. So i want the vlookup to go to the last cell possible with the data.
I have tried these two ways of calling vlookup, but nothing seems to work.
1.
Code:
With Worksheets(2).Range("B1")
.Formula = "=vlookup(A1,Sheet1!'$A1:$F50,1,FALSE)"
.Value = .Value
End With
Range("B1").Select
Selection.Autofill Destination:=Range("B1:B50")
2.
Code:
Range("B1").Select
ActiveCell.FormulaR1C1 = "=Vlookup(A1,Sheet1!'$A1:$F50,1,FALSE)"
Range("B1").Select
Selection.Autofill Destination:=Range("B1:B50")
In sheet 2 range can change depending on the data set. that is what i want to be flexible. The autofill range also needs to be flexible, which i am unable to do.