How to pass variables to an double match function in VBA

后端 未结 2 1860
独厮守ぢ
独厮守ぢ 2021-01-23 15:08

I have a bunch of rows and 25 columns in a worksheet, and need to find the value in the 4th column based on columns B and C using VBA. I am using a combination of index and mult

2条回答
  •  清歌不尽
    2021-01-23 15:24

    May be a bit quicker using memory arrays:

    Sub VariablesInArrayFormula()
    Dim SA As String
    SA = "Apples"
    
    Dim C1 As String
    C1 = "Oranges"
    
    With Worksheets("Sheet1") 'Change to your worksheet
        Dim DtaArray As Variant
        DtaArray = .Range("B2:D27").Value
    
        Dim i As Long
        For i = LBound(DtaArray, 1) To UBound(DtaArray, 1)
            Dim ans
            If DtaArray(i, 1) = SA And dtaaray(i, 2) = C1 Then
                ans = DtaArray(i, 3)
                Exit For
            End If
        Next i
    
        .Range("G1").Value = ans
    End With
    
    
    End Sub
    

提交回复
热议问题