Is there a way to use the FIND method to search for 1 of 2 alternative values? Set d = .Find(What:=[a OR b])
EDIT: Thanks for the UNION suggestions. I had no idea that was possible or I would've provided more detail originally to make the question more clear. So here's a 2nd try:
I have 3 columns. A is filled with dates. B is a code. And D is where I need to insert a function. The function will evaluate the code in colB and if the code is a "2", it will run the FIND method to find the nearest previous code 1 OR 2 in colB, then it will subtract the dates from colA on the two rows. For example:
A |B ...|D
[date1] |5 |[function does nothing]
[date2] |1 |[function does nothing]
[date3] |3 |[function does nothing]
[date4] |2 |[code 2 found, function inserts result of [date4]-[date2]
(last row would be same if 2nd row had a code 2 instead of a 1)
Here's the code I have now:
Private Function FindPrevActionCode(ActionCodeCell As Range, SearchCode As Byte)
'ActionCodeCell is the cell to check, search the value of that cell
'SearchCode is the code to look for
Dim d As Range 'Holds result of Find method
If ActionCodeCell.Value = 2 Then
With Worksheets(AppTab).Columns(cnAppActionCode)
Set d = .Find(What:=SearchCode, After:=ActionCodeCell, _
LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
MatchCase:=False, SearchFormat:=False)
End With
FindPrevActionCode = Cells(ActionCodeCell.row, cnAppTransEffDate).Value
- Cells(d.row, cnAppTransEffDate).Value
End If
End Function