![]() |
How to test text case for Upper/Lower/Proper
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 |
How to test text case for Upper/Lower/Proper
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 "JS" wrote in message ... 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 |
How to test text case for Upper/Lower/Proper
Hi Chip
Thanks, thanks, thanks... works like a charm... Nothing like one who knows... Cheers & thanks again, JS "Chip Pearson" wrote in message ... 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 "JS" wrote in message ... 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 |
All times are GMT +1. The time now is 08:08 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com