Forum Discussion

ccivitella01's avatar
ccivitella01
Copper Contributor
Feb 05, 2021

Vlookup help

I have a spreadsheet where I need to lookup a value based on a drop down menu that changes for the period and year.

 

Variance Tab

Data Tab

I am trying to get a return value of ($23,312.78) on the Variance Tab in cell D4.

 

This is the formula that I have:  =IF(ISERROR(VLOOKUP(B3&C3&D2,Data,4,FALSE)),0,VLOOKUP(B3&C3&D3,Data,4,FALSE))

B3 is the period from the Variance Tab, C3 is the year from the variance tab and D2 is the Line that I want to look up.  It is a merged field that combines D2 and D3.

Data is the range that I named for the information on the Data tab.

4 is the column on the data tab that I need the information from.

 

The return value is 0.  What I am doing wrong in my formula?

 

thanks,

16 Replies

  • ccivitella01 

    Use this, confirmed with Ctrl+Shift+Enter to turn it onto an array formula:

     

    =IFERROR(INDEX(Data!$D$2:$D$100, MATCH(1, (Data!$A$2:$A$100=D2)*(Data!$B$2:$B$100=C3)*(Data!$C$2:$C$100=B3), 0)), "")

     

    Adjust the ranges if needed.

    • ccivitella01's avatar
      ccivitella01
      Copper Contributor
      Hi Hans,

      With vlookup you can vlookupcomment. Can you do the same with index match?
      • HansVogelaar's avatar
        HansVogelaar
        MVP

        ccivitella01 

        VlookupComment is not a built-in function, but a custom VBA function (see How to vlookup and return matching value with cell comment?)

        You'd need a custom function here too. For example

        Function IndexMatchComment(DataRange As Range, ParamArray Conditions()) As Variant
            ' Adapted from Extendoffice
            Dim r As Long
            Dim i As Long
            Dim f As Boolean
            Dim s As String
            Dim xRet As Variant 'could be an error
            Dim xCell As Range
            Application.Volatile
            With Application.Caller
                If Not .Comment Is Nothing Then
                    .Comment.Delete
                End If
            End With
            For r = 1 To DataRange.Rows.Count
                f = True
                For i = 0 To UBound(Conditions) Step 2
                    If Conditions(i)(r) <> Conditions(i + 1) Then
                        f = False
                        Exit For
                    End If
                Next i
                If f Then
                    Set xCell = DataRange.Cells(r, 1)
                    IndexMatchComment = xCell.Value
                    With Application.Caller
                        If Not xCell.Comment Is Nothing Then
                            .AddComment xCell.Comment.Text
                        End If
                    End With
                    Exit Function
                End If
            Next r
            IndexMatchComment = "N/A"
        End Function

        Use like this in D4 on the Variance sheet:

         

        =IndexMatchComment(Data!$D$2:$D$5,Data!$A$2:$A$5,Sheet5!D$2,Data!$B$2:$B$5,Sheet5!$C3,Data!$C$2:$C$5,Sheet5!$B3)

         

        Fill to the right.

         

        ā€ƒ

Resources