Macro to vlookup multiple columns

Keshav14

New Member
Joined
Jul 1, 2019
Messages
1
Hi,

I need to populate almost 10 columns with information from another excel sheet. We usually do it using vlookup.
Can we use a macro and automate it. SO that I just click once and all the columns gets populates.

Table A where the information needs to be populated
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]IP[/TD]
[TD]Location[/TD]
[TD]Metal category[/TD]
[TD]Teams[/TD]
[TD]Application Hosted[/TD]
[TD]Owner[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1.1.1.1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1.1.1.2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1.1.1.3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1.1.1.2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]









Table B which contains information which is required in table A
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]IP[/TD]
[TD]Location[/TD]
[TD]Metal Category[/TD]
[TD]Teams[/TD]
[TD]Application Hosted[/TD]
[TD]Owner[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1.1.1.1[/TD]
[TD]UK[/TD]
[TD]Iron[/TD]
[TD]Windows[/TD]
[TD]MS Outlook[/TD]
[TD]A[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1.1.1.2[/TD]
[TD]USA[/TD]
[TD]Iron[/TD]
[TD]Unix[/TD]
[TD]Email[/TD]
[TD]B[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1.1.1.3[/TD]
[TD]Australia[/TD]
[TD]Gold[/TD]
[TD]Unix[/TD]
[TD]Sharepoint[/TD]
[TD]A[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1.1.1.4[/TD]
[TD]UK[/TD]
[TD]Silver[/TD]
[TD]Unix[/TD]
[TD]Sharepoint[/TD]
[TD]A[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1.1.1.5[/TD]
[TD]India[/TD]
[TD]Bronze[/TD]
[TD]Windows[/TD]
[TD]Vmware[/TD]
[TD]C[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]












Regards,
Keshav
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
How about
Code:
Sub Keshav14()
    Dim Cl As Range
    Dim Ws1 As Worksheet, Ws2 As Worksheet
    
    Set Ws1 = Sheets("sheet1")
    Set Ws2 = Sheets("sheet2")
    With CreateObject("scripting.dictionary")
        For Each Cl In Ws2.Range("A2", Ws2.Range("A" & Rows.Count).End(xlUp))
            .Item(Cl.Value) = Cl.Offset(, 1).Resize(, [COLOR=#ff0000]5[/COLOR])
        Next Cl
        For Each Cl In Ws1.Range("A2", Ws1.Range("A" & Rows.Count).End(xlUp))
            Cl.Offset(, 1).Resize(, [COLOR=#ff0000]5[/COLOR]).Value = .Item(Cl.Value)
        Next Cl
    End With
End Sub
Change the values in red to match the number of columns you want to copy.
 
Upvote 0
Cross posted https://www.excelforum.com/excel-pr...281146-macro-to-vlookup-multiple-columns.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

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