A
aztecbrainsurgeon
No question here, just a custom function example for the archive.
Test if A (or a combination of characters) is positioned to the
left of B (or a combination of characters) by specified spaces in
between A and B
case sensitivity is an optional arguement in function
Function NearEachOther(TargetCell As String, CompareChar As String,
Next2ThisChar As String, SpacesInBetween As Long, Optional
casesensitive) As Boolean
' Returns TRUE if A (or a combination of characters) is positioned to
the
'left of B (or a combination of characters) by specified spaces in
between A and B
If CompareChar = "" Or TargetCell = "" Then
NearEachOther = Evaluate("NA()")
Exit Function
End If
If IsMissing(casesensitive) Then casesensitive = 0
Select Case casesensitive
'Note: currently this function is set up to check if A is
positioned
' the LEFT of B (A_B). To check for A to the RIGHT of B (B_A),
'edit the section below by switching the places of string variables
'CompareChar and Next2ThisChar in the code.
Case 0 ''zero or missing
If TargetCell Like "*" & CompareChar &
WorksheetFunction.Rept(Chr(63), SpacesInBetween) & Next2ThisChar & "*"
Then NearEachOther = True Else NearEachOther = False
Case Else ''any non-zero 3rd argument
If UCase(TargetCell) Like "*" & UCase(CompareChar) &
WorksheetFunction.Rept(Chr(63), SpacesInBetween) & UCase(Next2ThisChar)
& "*" Then NearEachOther = True Else NearEachOther = False
End Select
End Function
Seach criteria:
proximity test for characters test for character positions near each
other
evaluate character positions check for character positioning
evaluate character order in string find specific character spacing are
specific characters next
to or near each other? evaluate spacing
Test if A (or a combination of characters) is positioned to the
left of B (or a combination of characters) by specified spaces in
between A and B
case sensitivity is an optional arguement in function
Function NearEachOther(TargetCell As String, CompareChar As String,
Next2ThisChar As String, SpacesInBetween As Long, Optional
casesensitive) As Boolean
' Returns TRUE if A (or a combination of characters) is positioned to
the
'left of B (or a combination of characters) by specified spaces in
between A and B
If CompareChar = "" Or TargetCell = "" Then
NearEachOther = Evaluate("NA()")
Exit Function
End If
If IsMissing(casesensitive) Then casesensitive = 0
Select Case casesensitive
'Note: currently this function is set up to check if A is
positioned
' the LEFT of B (A_B). To check for A to the RIGHT of B (B_A),
'edit the section below by switching the places of string variables
'CompareChar and Next2ThisChar in the code.
Case 0 ''zero or missing
If TargetCell Like "*" & CompareChar &
WorksheetFunction.Rept(Chr(63), SpacesInBetween) & Next2ThisChar & "*"
Then NearEachOther = True Else NearEachOther = False
Case Else ''any non-zero 3rd argument
If UCase(TargetCell) Like "*" & UCase(CompareChar) &
WorksheetFunction.Rept(Chr(63), SpacesInBetween) & UCase(Next2ThisChar)
& "*" Then NearEachOther = True Else NearEachOther = False
End Select
End Function
Seach criteria:
proximity test for characters test for character positions near each
other
evaluate character positions check for character positioning
evaluate character order in string find specific character spacing are
specific characters next
to or near each other? evaluate spacing