Private Sub ExecuteSearch_Click()
Range("D2").Value = ""
Dim CompareBasis As String, _
CodeList As Range, _
AssetCode As Range, _
FoundCount As Long, _
CompareTail As Long, _
AssetTail As Long, _
LessThan As Long, _
GreaterThan As Long
Set CodeList = Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
CompareBasis = UCase(SearchParam.Text)
'check for "<>" in comparison string
LessThan = InStr(SearchParam.Text, "<")
GreaterThan = InStr(SearchParam.Text, ">")
If LessThan Or GreaterThan Then
'strip off the last characters starting with "< & >"
CompareBasis = Left(CompareBasis, WorksheetFunction.Max(LessThan, GreaterThan) - 1)
' get number at end of compare string
CompareTail = CLng(Mid(SearchParam.Text, WorksheetFunction.Max(LessThan, GreaterThan) + 1))
End If
For Each AssetCode In CodeList
If AssetCode Like CompareBasis Then
If LessThan Or GreaterThan Then
'get number at end of asset code
AssetTail = CLng(Mid(AssetCode.Value, InStrRev(AssetCode.Value, " ") + 1))
If LessThan And AssetTail < CompareTail Then FoundCount = FoundCount + 1
If GreaterThan And AssetTail > CompareTail Then FoundCount = FoundCount + 1
Else
FoundCount = FoundCount + 1
End If
End If
Next AssetCode
Range("D2").Value = FoundCount
End Sub
Bookmarks