Vlookup Error

GirishDhruva

Active Member
Joined
Mar 26, 2019
Messages
308
Hi Everyone,

Here i am trying with Vlookup for a dynamic range of values , but if i run the below code i would only get the value for that particular 'A4' and remaining all values would be in #N/A.

And i am trying the lookup_Value and column_index_number also in a dynamic way(means col_index_number might vary for every month so i need to find that column through column names and from that column names i should find the column number and place that in the formula) , and for lookup_value it should increment by 1 after every loop, can this be done ?????????

where from formula highlighted ,A4 is lookup_value and 3 is the column_index_number

Code:
Sub Vlookup_Dynamic_Range()
    Dim myRow, LastRow As Long, myRng As Range
    With Sheet2


        myRow = 4
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row


        Do While myRow <= LastRow
        
            Worksheets("Sheet2").Activate
            Set myRng = Range(Cells(myRow, 1), Cells(myRow, 9))
            Worksheets("Sheet1").Activate
            ActiveCell.Offset(myRow - 4, 0).Formula = "=VLOOKUP([COLOR=#ff0000]A4[/COLOR], " & myRng.Address(external:=True) & ", [COLOR=#ff0000]3[/COLOR], false)"
            myRow = myRow + 1


        Loop
    End With


End Sub

Thank you in prior
 
How can i make my table to absolute reference so that my table values wouldn't be changed and i wouldn't get the error #N/A for the above code

Thank you in advance
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
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