MatchIf2Up

Search for 2 items in 2 columns starting from last row upword (Starting with StartFromRowUP up to row 1)
\Edit 2024-05-16: Newer version to accept wild card * in searching for Val1 and Val2

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 item in column 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 Like Val1 And Workbooks(WB).Worksheets(Shee).Range(Col1 & X1).Value > "" And Val1 > "" _
            And Workbooks(WB).Worksheets(Shee).Range(Col2 & X1).Value Like Val2 And Workbooks(WB).Worksheets(Shee).Range(Col2 & X1).Value > "" And 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 507

Downloads 49

CodeID
DB ID