VBA Vlookup another sheet

lotto009

New Member
Joined
Sep 19, 2012
Messages
23
Dear Friend
How to edit code VBA for the VBA Vlookup another sheet please see table and ad visor
VeVF7L
:eeek:
Thank you
lotto Beginner VBA
Sheet1
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]item[/TD]
[TD]Detail[/TD]
[TD]Age[/TD]
[TD]School name[/TD]
[TD]Mother[/TD]
[TD]Country[/TD]
[TD]parent[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]david[/TD]
[TD]17[/TD]
[TD][/TD]
[TD]T
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]job[/TD]
[TD]12[/TD]
[TD][/TD]
[TD]G[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]steep[/TD]
[TD]13[/TD]
[TD][/TD]
[TD]H[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]art[/TD]
[TD]15[/TD]
[TD][/TD]
[TD]I[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]









Sheet2
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]item[/TD]
[TD]detail[/TD]
[TD]School name[/TD]
[TD]teacher[/TD]
[TD]parent[/TD]
[TD]village[/TD]
[TD]Country[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]david[/TD]
[TD]BNK[/TD]
[TD]U[/TD]
[TD]P[/TD]
[TD]12[/TD]
[TD]VN[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]job[/TD]
[TD]STK[/TD]
[TD]I[/TD]
[TD]O[/TD]
[TD]23[/TD]
[TD]US[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]steep[/TD]
[TD]MONG[/TD]
[TD]K[/TD]
[TD]I[/TD]
[TD]45[/TD]
[TD]JAPAN[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]art[/TD]
[TD]KIWI[/TD]
[TD]L[/TD]
[TD]Q[/TD]
[TD]66[/TD]
[TD]Thai[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi lotto009,

What sheet / column(s) do you want to look up from from which sheet / column(s)? Is it the three missing fields (columns) from Sheet1 you've shown here? Why does it have to be VBA?

Robert
 
Upvote 0
Dear Trebor76
I need used to VBA code because many columns and many sheets (vlookup by formula is fine for me I can do)
Thank you
Biginner
 
Upvote 0
Though you didn't answer all my questions see if this is what you're after (assumes data is in columns A to G):

Code:
Option Explicit
Sub Macro1()

    Dim lngLastRow As Long
    Dim wsOutput   As Worksheet
    Dim wsSource   As Worksheet
    
    Application.ScreenUpdating = False
    
    Set wsOutput = Sheets("Sheet1") 'Sheet name for the following VBA to fill in
    Set wsSource = Sheets("Sheet2") 'Sheet name containing completed data for VLOOKUP

    lngLastRow = wsOutput.Range("A:G").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    With wsOutput
        'Formula for School Name
        With .Range("D2:D" & lngLastRow)
            .Formula = "=VLOOKUP(A2,'" & CStr(wsSource.Name) & "'!A:G,3,FALSE)"
            .Value = .Value 'Convert above formula to a value.  Comment out or remove if you want the formula to remain
        End With
        'Formula for Country
        With .Range("F2:F" & lngLastRow)
            .Formula = "=VLOOKUP(A2,'" & CStr(wsSource.Name) & "'!A:G,7,FALSE)"
            .Value = .Value 'Convert above formula to a value.  Comment out or remove if you want the formula to remain
        End With
         'Formula for Parent
        With .Range("G2:G" & lngLastRow)
            .Formula = "=VLOOKUP(A2,'" & CStr(wsSource.Name) & "'!A:G,5,FALSE)"
            .Value = .Value 'Convert above formula to a value.  Comment out or remove if you want the formula to remain
        End With
    End With
                  
    Set wsOutput = Nothing
    Set wsSource = Nothing
    
    Application.ScreenUpdating = True

End Sub

Robert
 
Upvote 0
WOWW is WORK
Thank you for you kindly Khun Trebor76 to support I will learn your code and adept to my file
Thank you krab
lotto 's Biginner vba
 
Last edited:
Upvote 0
You're welcome. I'm glad we were able to provide you with a solution :)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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