View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_2374_] Rick Rothstein \(MVP - VB\)[_2374_] is offline
external usenet poster
 
Posts: 1
Default Detect UPPERCASE in cell value?

Special thanks to Rick Rothstein (MVP - VB) who helped me
figure out how to finally use wildcard characters correctly!!!

'========== WILDCARD SEARCH
Function WildCard(Text As String) As Boolean
WildCard = Text Like "*" & UserForm1.TextBox1.Value & "*"
End Function

'-------------------- USERFORM SEARCH BUTTON
Private Sub CommandButton1_Click()
Range("C2:C12").FormulaR1C1 = "=WildCard(RC[-2])"
Application.Calculate
End Sub

Rick, I can't tell you how long I've been searching for code to
do exactly what this does here... This just made all the really
advanced programs I design even better!!


I'm glad you were able to get something out of my posted code. Just to note,
however, that your WildCard function performs a case-sensitive search. If
you wanted it to be case-insensitive, you would have to apply the either the
UCase or the LCase function to both the Text argument and the TextBox value
in the Like comparison. You might find the function more flexible in this
regard...

Function WildCard(Text As String, Optional _
CaseSensitive As Boolean = True) As Boolean
WildCard = InStr(1, UserForm1.TextBox1.Value, _
Text, Abs(CaseSensitive)) 0
End Function

The default is to do a case-sensitive search as is done now; but if you
supply False (or 0) for the optional 2nd argument, then the search will be
performed case-insensitive. Also note that I did not use the Like operator
for this function... its main strength is when you want to look into
specific characters rather than testing the whole text (not that it can't be
used that way, but the InStr function is marginally faster).

Rick