VBA Vlookup another sheet

lotto009

New Member
Joined
Sep 19, 2012
Messages
16
Dear Friend
How to edit code VBA for the VBA Vlookup another sheet please see table and ad visor
:eek:
Thank you
lotto Beginner VBA
Sheet1
itemDetailAgeSchool nameMotherCountryparent
1david17T
2job12G
3steep13H
4art15I

<tbody>
</tbody>









Sheet2
itemdetailSchool nameteacherparentvillageCountry
1davidBNKUP12VN
2jobSTKIO23US
3steepMONGKI45JAPAN
4artKIWILQ66Thai

<tbody>
</tbody>
 

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
4,467
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
 

lotto009

New Member
Joined
Sep 19, 2012
Messages
16
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
 

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
4,467
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
 

lotto009

New Member
Joined
Sep 19, 2012
Messages
16
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:

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
4,467
You're welcome. I'm glad we were able to provide you with a solution :)
 

Forum statistics

Threads
1,081,972
Messages
5,362,495
Members
400,677
Latest member
champchamp

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top