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
:eek:
Thank you
lotto Beginner VBA
Sheet1
itemDetailAgeSchool nameMotherCountryparent
1david17T
2job12G
3steep13H
4art15I

<tbody>
</tbody>









Sheet2
itemdetailSchool nameteacherparentvillageCountry
1davidBNKUP12VN
2jobSTKIO23US
3steepMONGKI45JAPAN
4artKIWILQ66Thai

<tbody>
</tbody>
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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