Extract the data from One workbook to another workbook

     

  • This program enables the user to extract the data from one workbook to another by using Vlookup function
  • Click on below mentioned image to watch the video
  •  

    Download The Workbook

     

    Sub ExtractTheDataFromOneWorkbookToAnotherByUsingVLookup()

    'Define the Lookup File Name
    Dim LkpFileName As String
    LkpFileName = Application.GetOpenFilename

    'Open the LookupWorkbook
    Workbooks.Open (LkpFileName)

    'Create Variable for Lookup Workbook
    Dim LkpWkb As Workbook
    Set LkpWkb = ActiveWorkbook

    'Define the worksheet which consists of Lookup value
    Dim LkpSh As Worksheet
    Set LkpSh = LkpWkb.Sheets("Sheet1")

    'Define the Lookup value
    Dim LookupValue As String
    LookupValue = "'[" & LkpSh.Parent.Name & "]" & LkpSh.Name & "'!A2"

    'Define the DataBase file Name
    Dim DBFileName As String
    DBFileName = Application.GetOpenFilename

    'Open the Database workbook
    Workbooks.Open (DBFileName)

    'Create Variable for Database workbook
    Dim DBWkb As Workbook
    Set DBWkb = ActiveWorkbook

    'Create Variable for DataRange worksheet
    Dim DBSh As Worksheet
    Set DBSh = DBWkb.Sheets("Sheet1")

    'Define the Lookup Range
    Dim LookupRng As String
    LookupRng = "'[" & DBSh.Parent.Name & "]" & DBSh.Name & "'!$A$2:$B$12"

    'Create Lookup Formula
    LkpSh.Range("B2").Value = "=Vlookup(" & LookupValue & "," & LookupRng & "," & 2 & "," & 0 & ")"

    'Filldown the Formula to all the data range
    With LkpSh
    LkpSh.Range("B2:B12").FillDown
    End With

    End Sub