Check for uppercase letters in VBA

lighty

New Member
Joined
Dec 1, 2014
Messages
2
Hello, I am new to VBA and I need to make a function that checks for uppercase letters in Strings. I have tried searching the web but I only managed to find checks for the first letter.
The Strings can also contain numbers.
I just need to check if the letter in a String is uppercase or not, that is all.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Not really sure what you want. If you enter a formula on an excel sheet:
=upCase(A2)
and there is an Upper Case letter in the string, it will return a message box with Yes. Otherwise it returns nothing and posts a zero in the sell with the formula. If you call the function in code"
Code:
upCase Range("A2"
It displays the message box if there is an Upper Case letter, or ignores it and does nothing if there is none.
Code:
Function upCase(rng As Range)
Dim uc As String
For i = 1 To Len(rng.Value)
    uc = (Mid(rng.Value, i, 1))
    If uc = UCase(uc) Then
        MsgBox "Yes"  
    End If
Next
End Function
 
Last edited:
Upvote 0
Welcome to the board.

Row\Col
A​
B​
C​
1​
My dog has fleas
TRUE​
B1: =HasCap(A1)
2​
my dog has fleas
FALSE​
3​
123ab
FALSE​
4​
22Skidoo
TRUE​

Code:
Function HasCap(sInp As String) As Boolean
  HasCap = sInp Like "*[A-Z]*"
End Function
 
Upvote 0
Hi and welcome to the MrExcel Message Board.

Is the Like command what you need?

Code:
If "awCd " Like "*[A-Z]*" Then Debug.Print "Found" Else Debug.Print "Not found"

This HELP is for VB but it seems to apply to VBA as well: Like Operator (Visual Basic)

Regards,
 
Upvote 0
Thank you guys, these are all usefull. Though, I found the second solution easiest to use.
Thank you all for the contribution, you have a nice forum!
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,134
Members
449,206
Latest member
burgsrus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top