Extract the Data from One workbook to another using Index and Match Functions

     

    How Index + Match Functions are different from VLookup Function

     

     

    State the difference between Match function and VLookup Function

     

     

  • Click on Below mentioned Image to watch the video:
  •  

    Download the Workbook

     

    Copy the code:

    Sub ExtractTheDataFromOneWorkbookToAnotherByUsingIndexAndMatch()

    'Define Output File Name
    Dim OutputFileName As String
    OutputFileName = Application.GetOpenFilename

    'Open the Output Workbook
    Workbooks.Open (OutputFileName)

    'Create the Variable for Output Workbook
    Dim OutputWkb As Workbook
    Set OutputWkb = ActiveWorkbook

    'Define the worksheet which consists of Lookup Data
    Dim OutputSh As Worksheet
    Set OutputSh = OutputWkb.Sheets("OutputSH")

    'Define the Lookup value for Match function
    Dim LookupValue As String
    LookupValue = "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("DataBase")

    'Define the Lookup Array for Match Function
    Dim LookUpArray As String
    LookUpArray = "'[" & DBSh.Parent.Name & "]" & DBSh.Name & "'!C$1:C$12"

    'Define the Array Range for Index function
    Dim IndexArrayRng As String
    IndexArrayRng = "'[" & DBSh.Parent.Name & "]" & DBSh.Name & "'!$A$1:$E$12"

    'Create Formula after combining Index and Match functions
    OutputSh.Range("B2").Value = "=Index(" & IndexArrayRng & "," & "Match(" & LookupValue & "," & LookUpArray & "," & 0 & ")" & "," & 1 & ")"
    OutputSh.Range("C2").Value = "=Index(" & IndexArrayRng & "," & "Match(" & LookupValue & "," & LookUpArray & "," & 0 & ")" & "," & 2 & ")"
    OutputSh.Range("D2").Value = "=Index(" & IndexArrayRng & "," & "Match(" & LookupValue & "," & LookUpArray & "," & 0 & ")" & "," & 4 & ")"
    OutputSh.Range("E2").Value = "=Index(" & IndexArrayRng & "," & "Match(" & LookupValue & "," & LookUpArray & "," & 0 & ")" & "," & 5 & ")"

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

    End Sub