ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check to see if entire string is UpperCase? (https://www.excelbanter.com/excel-programming/439666-check-see-if-entire-string-uppercase.html)

msnyc07

Check to see if entire string is UpperCase?
 
I know I can check if an individual character is uppercase If X Like "[A-Z]"
but is there a way to check if a string of indeterminate length is all
uppercase?

Dave Peterson

Check to see if entire string is UpperCase?
 
if ucase(myStr) = mystr then
'it looks the same as uppercase

But if your string looks like:

myStr = "7!@#$_-==--"

Then upper/lower case doesn't really make sense.



msnyc07 wrote:

I know I can check if an individual character is uppercase If X Like "[A-Z]"
but is there a way to check if a string of indeterminate length is all
uppercase?


--

Dave Peterson

ker_01

Check to see if entire string is UpperCase?
 
If myString = UCase(Mystring) then 'the string is fully uppercase

HTH,
Keith

"msnyc07" wrote:

I know I can check if an individual character is uppercase If X Like "[A-Z]"
but is there a way to check if a string of indeterminate length is all
uppercase?


Rick Rothstein

Check to see if entire string is UpperCase?
 
The Like operator allows wildcards...

If Not X Like "*[a-z]*" Then
' X does not contain any lower case letters which
' doesn't mean every letter is an upper case letter...
' there could be punctuation marks or blanks
Else
' X does not contain any lower case letters
End If

--
Rick (MVP - Excel)


"msnyc07" wrote in message
...
I know I can check if an individual character is uppercase If X Like
"[A-Z]"
but is there a way to check if a string of indeterminate length is all
uppercase?



Joe User[_2_]

Check to see if entire string is UpperCase?
 
"msnyc07" wrote:
I know I can check if an individual character is
uppercase If X Like "[A-Z]" but is there a way
to check if a string of indeterminate length is all
uppercase?


Both of the of following should work, assuming s is String and isUCase is
Boolean. I don't know which is more efficient.

isUCase = (s Like "*[A-Z]*" And Not s Like "*[a-z]*")

isUCase = (s = UCase(s) And s < LCase(s))

Note that these return False for a string without any uppercase character.

Rick Rothstein

Check to see if entire string is UpperCase?
 
' X does not contain any lower case letters which
' doesn't mean every letter is an upper case letter...
' there could be punctuation marks or blanks


The above comment should have read this way (with the correction shown in
upper case)...

' X does not contain any lower case letters which
' doesn't mean every CHARACTER is an upper case letter...
' there could be punctuation marks or blanks

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
The Like operator allows wildcards...

If Not X Like "*[a-z]*" Then
' X does not contain any lower case letters which
' doesn't mean every letter is an upper case letter...
' there could be punctuation marks or blanks
Else
' X does not contain any lower case letters
End If

--
Rick (MVP - Excel)


"msnyc07" wrote in message
...
I know I can check if an individual character is uppercase If X Like
"[A-Z]"
but is there a way to check if a string of indeterminate length is all
uppercase?




Dana DeLouis[_3_]

Check to see if entire string is UpperCase?
 
On 2/17/2010 6:23 PM, msnyc07 wrote:
I know I can check if an individual character is uppercase If X Like "[A-Z]"
but is there a way to check if a string of indeterminate length is all
uppercase?


Just to throw this out in case one uses 'Option Compare'

Option Explicit
Option Compare Text

Sub Demo()
Dim s
s = "abC"

'True, but not correct
Debug.Print UCase(s) = s

'False..Correct
Debug.Print SameQ(s, UCase(s))
End Sub

Function SameQ(s1, s2)
SameQ = StrComp(s1, s2, vbBinaryCompare) = 0
End Function

= = = = = = =
HTH :)
Dana DeLouis


All times are GMT +1. The time now is 10:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com