PC Review


Reply
Thread Tools Rate Thread

Check to see if entire string is UpperCase?

 
 
msnyc07
Guest
Posts: n/a
 
      17th Feb 2010
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?
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      17th Feb 2010
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
 
Reply With Quote
 
ker_01
Guest
Posts: n/a
 
      17th Feb 2010
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?

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      18th Feb 2010
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" <(E-Mail Removed)> wrote in message
news:9EDC8758-93BD-46BD-A073-(E-Mail Removed)...
>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?


 
Reply With Quote
 
Joe User
Guest
Posts: n/a
 
      18th Feb 2010
"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.
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      18th Feb 2010
> ' 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:9EDC8758-93BD-46BD-A073-(E-Mail Removed)...
>>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?

>


 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      18th Feb 2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if string contain Uppercase. Ken Microsoft VB .NET 2 2nd May 2007 07:31 PM
Changing the entire contents of my spreadsheet to uppercase =?Utf-8?B?QnJpYW4gRGVubnk=?= Microsoft Excel Misc 7 19th Nov 2006 11:21 PM
Can I make an entire column Uppercase? =?Utf-8?B?SmFjaw==?= Microsoft Excel Misc 3 31st Mar 2006 02:11 AM
anyway to change an entire document to uppercase in excel? =?Utf-8?B?a3Jpc3RlbA==?= Microsoft Excel Misc 1 13th Jan 2006 12:29 AM
How can I convert entire columns of text to Uppercase in Excel? =?Utf-8?B?ZHBsYW50bGFkeQ==?= Microsoft Excel Worksheet Functions 8 1st May 2005 06:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:42 AM.