Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default 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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default 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.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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?



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the entire contents of my spreadsheet to uppercase Brian Denny Excel Discussion (Misc queries) 7 November 19th 06 11:21 PM
How do change entire worksheet to uppercase letters and lock it aeromutt Excel Worksheet Functions 2 April 1st 06 05:04 PM
Can I make an entire column Uppercase? Jack Excel Discussion (Misc queries) 3 March 31st 06 02:11 AM
anyway to change an entire document to uppercase in excel? kristel Excel Discussion (Misc queries) 1 January 13th 06 12:29 AM
How can I convert entire columns of text to Uppercase in Excel? dplantlady Excel Worksheet Functions 8 May 1st 05 06:51 PM


All times are GMT +1. The time now is 05:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"