I seem to know a lot of ways to calculate the non-zero min in Excel... but no slick way in VBA.
Problem: Want to find the first instance of either the ":" or "-" characters in a string. The user always enters either ":" or "-" but usually not both.
So far the best I got is:
Problem: Want to find the first instance of either the ":" or "-" characters in a string. The user always enters either ":" or "-" but usually not both.
So far the best I got is:
Code:
lngColonPosition = InStr(1, Text, ":")
lngHyphenPosition = InStr(1, Text, "-")
If lngColonPosition = 0 And lngHyphenPosition = 0 Then
' we're in trouble
ElseIf lngColonPosition = 0 And lngHyphenPosition <> 0 Then
lngFirstInstance = lngHyphenPosition
ElseIf lngColonPosition <> 0 And lngHyphenPosition = 0 Then
lngFirstInstance = lngColonPosition
Else
lngFirstInstance = Min(lngColonPosition, lngHyphenPosition)
End If