MatchIf2Up

Search for 2 items in 2 columns starting from last row upword (Starting with StartFromRowUP up to row 1)

CodeFunctionName
What is this?

Public

Tested

Original Work
Function MatchIf2Up(Val1, Col1, Val2, Col2, Optional WB = "This", Optional Shee = "Active", Optional StartFromRowUP = 100)
    '
    ' Will search for 2 items in 2 columns starting from last row upword (StartFromRowUP)
    ' For two conditions at the same time
    Rett = 0
    If WB = "This" Then WB = ThisWorkbook.Name
    If WB = "Active" Then WB = ActiveWorkbook.Name
    If Shee = "Active" Then Shee = ActiveSheet.Name
    ColStart = Col1 & 1
    CoCo1 = WorksheetFunction.CountIf(Workbooks(WB).Worksheets(Shee).Range(ColStart, Col1 & StartFromRowUP), Val1)
    If CoCo1 = 0 Then GoTo ByeBye
    For X1 = StartFromRowUP - 1 To 1 Step -1
        If Workbooks(WB).Worksheets(Shee).Range(Col1 & X1).Value = Val1 And Workbooks(WB).Worksheets(Shee).Range(Col2 & X1).Value = Val2 Then
            Rett = X1
            Exit For
        End If
    Next
ByeBye:
    MatchIf2Up = Rett
End Function

Val1, Col1, Val2, Col2, Optional WB = "This", Optional Shee = "Active", Optional StartFromRowUP = 100

Views 390

Downloads 43

CodeID
DB ID