I need a function in VBA that finds the row number based on 2 where clauses.
Here is the Excel sample:
** A B C D**
1 id1
In VBA you can do a brute force check like the following:
Public Sub Test()
Dim message As String
Dim row As Long
row = Find("id1", "day2")
message = "Not Found"
If (row > 0) Then
message = ActiveSheet.Cells(row, 3).Value
End If
MsgBox message
End Sub
Function Find(aVal As String, bVal As String) As Long
Dim maxRow As Long
Dim row As Long
maxRow = Range("A65536").End(xlUp).row
For row = 2 To maxRow
Dim a As String
a = ActiveSheet.Cells(row, 1).Value
b = ActiveSheet.Cells(row, 2).Value
If a = aVal And b = bVal Then
Find = row
Exit Function
End If
Next row
Find = -1
End Function