How to test text case for Upper/Lower/Proper

J

JS

Hi All,
I'm trying to find a way to test case of certain text-strings to see if they
are upper, lower, proper, etc., in a VBA in Excel (similar to Word's VBA
Case functions (wdLowerCase, wdUpperCase, wdTitleSentence, wdTitleWord) - it
would be nice to have Excel functions: IsTextUpper, IsTextLower,
IsTextProper, etc.
Does anyone know how this may be done?
Thanks a lot - JS
 
C

Chip Pearson

Try some code like the following:

Dim S As String
S = "whatever"
If StrComp(S, UCase(S), vbBinaryCompare) = 0 Then
Debug.Print "UPPER CASE"
ElseIf StrComp(S, LCase(S), vbBinaryCompare) = 0 Then
Debug.Print "lower case"
ElseIf StrComp(S, StrConv(S, vbProperCase), vbBinaryCompare) = 0
Then
Debug.Print "Proper Case"
Else
Debug.Print "Mixed case"
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
J

JS

Hi Chip
Thanks, thanks, thanks... works like a charm...
Nothing like one who knows...
Cheers & thanks again, JS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top