PC Review


Reply
Thread Tools Rate Thread

Detect UPPERCASE in cell value?

 
 
Internetdomainowner@hotmail.com
Guest
Posts: n/a
 
      23rd Jul 2008
Fellow programmers... below is some code I tried to create to detect
if the contents of the ActiveCell.Value was all UPPERCASE. The
spreadsheet is importing data and if a cell's value is all updercase
it means something specific with the data that being imported. Any
ideas as to how to make a TRUE & FALSE statement based on the
characters being all uppdercase?

Declare Function IsCharUpper Lib "user32" Alias "IsCharUpperA" _
(ByVal cChar As Byte) As Long
Sub Button22221_Click()

If IsCharUpper(ActiveCell.Value) = True Then
MsgBox "It is bitch.", vbOKOnly, "-Test-"
End If

If IsCharUpper(ActiveCell.Value) = False Then
MsgBox "It's not uppercase.", vbOKOnly, "-Test 2-"
End If

End Sub


Thanks in advance!
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      23rd Jul 2008
Give this a try...

Public Function IsUpper(ByVal cell As Range) As Boolean
If cell.Value = UCase(cell.Value) Then
IsUpper = True
Else
IsUpper = False
End If
End Function
--
HTH...

Jim Thomlinson


"(E-Mail Removed)" wrote:

> Fellow programmers... below is some code I tried to create to detect
> if the contents of the ActiveCell.Value was all UPPERCASE. The
> spreadsheet is importing data and if a cell's value is all updercase
> it means something specific with the data that being imported. Any
> ideas as to how to make a TRUE & FALSE statement based on the
> characters being all uppdercase?
>
> Declare Function IsCharUpper Lib "user32" Alias "IsCharUpperA" _
> (ByVal cChar As Byte) As Long
> Sub Button22221_Click()
>
> If IsCharUpper(ActiveCell.Value) = True Then
> MsgBox "It is bitch.", vbOKOnly, "-Test-"
> End If
>
> If IsCharUpper(ActiveCell.Value) = False Then
> MsgBox "It's not uppercase.", vbOKOnly, "-Test 2-"
> End If
>
> End Sub
>
>
> Thanks in advance!
>

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      23rd Jul 2008
Your request is not totally clear. What if the contents of the cell have
numbers or punctuation marks included with its all uppercase letters...
would you want TRUE or FALSE for that condition? Also, do you really want a
VB coded function or would a worksheet formula be acceptable?

Rick


<(E-Mail Removed)> wrote in message
news:6139d6e2-9d0e-4ee9-ba9b-(E-Mail Removed)...
> Fellow programmers... below is some code I tried to create to detect
> if the contents of the ActiveCell.Value was all UPPERCASE. The
> spreadsheet is importing data and if a cell's value is all updercase
> it means something specific with the data that being imported. Any
> ideas as to how to make a TRUE & FALSE statement based on the
> characters being all uppdercase?
>
> Declare Function IsCharUpper Lib "user32" Alias "IsCharUpperA" _
> (ByVal cChar As Byte) As Long
> Sub Button22221_Click()
>
> If IsCharUpper(ActiveCell.Value) = True Then
> MsgBox "It is bitch.", vbOKOnly, "-Test-"
> End If
>
> If IsCharUpper(ActiveCell.Value) = False Then
> MsgBox "It's not uppercase.", vbOKOnly, "-Test 2-"
> End If
>
> End Sub
>
>
> Thanks in advance!


 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      23rd Jul 2008
Option Explicit
Sub Do_Uppercase()
Dim UpperCase

UpperCase = UCase(ActiveCell.Value)
If ActiveCell.Value = UpperCase Then
MsgBox "Ding", vbOKOnly
ElseIf ActiveCell.Value <> UpperCase Then
MsgBox "Nope", vbCritical
End If
End Sub


"(E-Mail Removed)" wrote:

> Fellow programmers... below is some code I tried to create to detect
> if the contents of the ActiveCell.Value was all UPPERCASE. The
> spreadsheet is importing data and if a cell's value is all updercase
> it means something specific with the data that being imported. Any
> ideas as to how to make a TRUE & FALSE statement based on the
> characters being all uppdercase?
>
> Declare Function IsCharUpper Lib "user32" Alias "IsCharUpperA" _
> (ByVal cChar As Byte) As Long
> Sub Button22221_Click()
>
> If IsCharUpper(ActiveCell.Value) = True Then
> MsgBox "It is bitch.", vbOKOnly, "-Test-"
> End If
>
> If IsCharUpper(ActiveCell.Value) = False Then
> MsgBox "It's not uppercase.", vbOKOnly, "-Test 2-"
> End If
>
> End Sub
>
>
> Thanks in advance!
>

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      23rd Jul 2008
Depending on your answer to my question AND assuming you want a VB function,
one of these should work for you. The first one reports True if Text is
composed **only** of letters and those letters are all uppercase; the second
allows Text to have non-letters as part of it and reports True as long as
the letter parts are uppercase...

Function IsUppercasedLettersOnly(Text As String) As Boolean
IsUppercasedLettersOnly = Not Text Like "*[!A-Z]*"
End Function

Function IsLetterPartUppercased(Text As String) As Boolean
IsLetterPartUppercased = Not Text Like "*[a-z]*"
End Function

If you would want a worksheet formula solution, you will still need to
answer my first question.

Rick


"Rick Rothstein (MVP - VB)" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Your request is not totally clear. What if the contents of the cell have
> numbers or punctuation marks included with its all uppercase letters...
> would you want TRUE or FALSE for that condition? Also, do you really want
> a VB coded function or would a worksheet formula be acceptable?
>
> Rick
>
>
> <(E-Mail Removed)> wrote in message
> news:6139d6e2-9d0e-4ee9-ba9b-(E-Mail Removed)...
>> Fellow programmers... below is some code I tried to create to detect
>> if the contents of the ActiveCell.Value was all UPPERCASE. The
>> spreadsheet is importing data and if a cell's value is all updercase
>> it means something specific with the data that being imported. Any
>> ideas as to how to make a TRUE & FALSE statement based on the
>> characters being all uppdercase?
>>
>> Declare Function IsCharUpper Lib "user32" Alias "IsCharUpperA" _
>> (ByVal cChar As Byte) As Long
>> Sub Button22221_Click()
>>
>> If IsCharUpper(ActiveCell.Value) = True Then
>> MsgBox "It is bitch.", vbOKOnly, "-Test-"
>> End If
>>
>> If IsCharUpper(ActiveCell.Value) = False Then
>> MsgBox "It's not uppercase.", vbOKOnly, "-Test 2-"
>> End If
>>
>> End Sub
>>
>>
>> Thanks in advance!

>


 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      23rd Jul 2008
Looking at Rick's code makes me think mine is just a tad bloated. Here is a
shorter version of mine...

Public Function IsUpper(ByVal cell As Range) As Boolean
IsUpper = cell.Value = UCase(cell.Value)
End Function
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

> Give this a try...
>
> Public Function IsUpper(ByVal cell As Range) As Boolean
> If cell.Value = UCase(cell.Value) Then
> IsUpper = True
> Else
> IsUpper = False
> End If
> End Function
> --
> HTH...
>
> Jim Thomlinson
>
>
> "(E-Mail Removed)" wrote:
>
> > Fellow programmers... below is some code I tried to create to detect
> > if the contents of the ActiveCell.Value was all UPPERCASE. The
> > spreadsheet is importing data and if a cell's value is all updercase
> > it means something specific with the data that being imported. Any
> > ideas as to how to make a TRUE & FALSE statement based on the
> > characters being all uppdercase?
> >
> > Declare Function IsCharUpper Lib "user32" Alias "IsCharUpperA" _
> > (ByVal cChar As Byte) As Long
> > Sub Button22221_Click()
> >
> > If IsCharUpper(ActiveCell.Value) = True Then
> > MsgBox "It is bitch.", vbOKOnly, "-Test-"
> > End If
> >
> > If IsCharUpper(ActiveCell.Value) = False Then
> > MsgBox "It's not uppercase.", vbOKOnly, "-Test 2-"
> > End If
> >
> > End Sub
> >
> >
> > Thanks in advance!
> >

 
Reply With Quote
 
Internetdomainowner@hotmail.com
Guest
Posts: n/a
 
      23rd Jul 2008
On Jul 23, 12:36*pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com> wrote:
> Looking at Rick's code makes me think mine is just a tad bloated. Here isa
> shorter version of mine...
>
> Public Function IsUpper(ByVal cell As Range) As Boolean
> * * IsUpper = cell.Value = UCase(cell.Value)
> End Function
> --
> HTH...
>
> Jim Thomlinson
>
>
>
> "Jim Thomlinson" wrote:
> > Give this a try...

>
> > Public Function IsUpper(ByVal cell As Range) As Boolean
> > * * If cell.Value = UCase(cell.Value) Then
> > * * * * IsUpper = True
> > * * Else
> > * * * * IsUpper = False
> > * * End If
> > End Function
> > --
> > HTH...

>
> > Jim Thomlinson

>
> > "Internetdomainow...@hotmail.com" wrote:

>
> > > Fellow programmers... below is some code I tried to create to detect
> > > if the contents of the ActiveCell.Value was all UPPERCASE. The
> > > spreadsheet is importing data and if a cell's value is all updercase
> > > it means something specific with the data that being imported. Any
> > > ideas as to how to make a TRUE & FALSE statement based on the
> > > characters being all uppdercase?

>
> > > Declare Function IsCharUpper Lib "user32" Alias "IsCharUpperA" _
> > > * (ByVal cChar As Byte) As Long
> > > Sub Button22221_Click()

>
> > > If IsCharUpper(ActiveCell.Value) = True Then
> > > MsgBox "It is bitch.", vbOKOnly, "-Test-"
> > > End If

>
> > > If IsCharUpper(ActiveCell.Value) = False Then
> > > MsgBox "It's not uppercase.", vbOKOnly, "-Test 2-"
> > > End If

>
> > > End Sub

>
> > > Thanks in advance!- Hide quoted text -

>
> - Show quoted text -


Thank you everyone -- you all have great solutions!!!

Special thanks to Rick Rothstein (MVP - VB) who helped me figure out
how to finally use wildcard characters correctly!!!

'========== WILDCARD SEARCH
Function WildCard(Text As String) As Boolean
WildCard = Text Like "*" & UserForm1.TextBox1.Value & "*"
End Function

'-------------------- USERFORM SEARCH BUTTON
Private Sub CommandButton1_Click()
Range("C2:C12").FormulaR1C1 = "=WildCard(RC[-2])"
Application.Calculate
End Sub

Rick, I can't tell you how long I've been searching for code to do
exactly what this does here... This just made all the really advanced
programs I design even better!!
 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      23rd Jul 2008
> Special thanks to Rick Rothstein (MVP - VB) who helped me
> figure out how to finally use wildcard characters correctly!!!
>
> '========== WILDCARD SEARCH
> Function WildCard(Text As String) As Boolean
> WildCard = Text Like "*" & UserForm1.TextBox1.Value & "*"
> End Function
>
> '-------------------- USERFORM SEARCH BUTTON
> Private Sub CommandButton1_Click()
> Range("C2:C12").FormulaR1C1 = "=WildCard(RC[-2])"
> Application.Calculate
> End Sub
>
> Rick, I can't tell you how long I've been searching for code to
> do exactly what this does here... This just made all the really
> advanced programs I design even better!!


I'm glad you were able to get something out of my posted code. Just to note,
however, that your WildCard function performs a case-sensitive search. If
you wanted it to be case-insensitive, you would have to apply the either the
UCase or the LCase function to both the Text argument and the TextBox value
in the Like comparison. You might find the function more flexible in this
regard...

Function WildCard(Text As String, Optional _
CaseSensitive As Boolean = True) As Boolean
WildCard = InStr(1, UserForm1.TextBox1.Value, _
Text, Abs(CaseSensitive)) > 0
End Function

The default is to do a case-sensitive search as is done now; but if you
supply False (or 0) for the optional 2nd argument, then the search will be
performed case-insensitive. Also note that I did not use the Like operator
for this function... its main strength is when you want to look into
specific characters rather than testing the whole text (not that it can't be
used that way, but the InStr function is marginally faster).

Rick

 
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
If Cell Contains specific UPPERCASE text GoBucks Microsoft Excel Worksheet Functions 8 20th May 2009 03:51 PM
Format cell to uppercase using code Pat Microsoft Excel Programming 5 12th Feb 2005 11:50 PM
Can sumif detect text strings or detect if a dollar sign $ is in a cell? MollyDavis Microsoft Excel Misc 4 17th Apr 2004 11:45 PM
Can sumif detect text strings or detect if a dollar sign $ is in a cell? MollyDavis Microsoft Excel Worksheet Functions 4 17th Apr 2004 11:45 PM
Forcing Uppercase in a cell =?Utf-8?B?WmFj?= Microsoft Excel Misc 6 12th Nov 2003 08:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:40 AM.