VBA- cells that contain lowercase letters

cheerz4325

New Member
Joined
Nov 5, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am looking for a code in vba excel that helps me highlight cells that contain lowercase letters pink. The code should start at => Range("table").CurrentRegion.

Thank you for your help!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You can try in this way...
VBA Code:
Sub HighlightLCaseCells()

    With Range("table").CurrentRegion
        For Each vC In .Cells
            For vN2 = 1 To Len(vC)
                If Mid(vC, vN2, 1) Like "[a-z]" Then _
                    vC.Interior.Color = RGB(255, 150, 255)
                    GoTo EX
            Next vN2
EX:     Next vC
    End With
    
End Sub
 
Upvote 0
cells that contain lowercase letters
Do you mean any lower case letters or do you mean all lower case letters?
For example, which of these cells would you want highlighted?

21 11 10.xlsm
A
1ABC
2abc
3Abc
4a123b
53456#@6
lower case
 
Upvote 0
You can try in this way...
VBA Code:
Sub HighlightLCaseCells()

    With Range("table").CurrentRegion
        For Each vC In .Cells
            For vN2 = 1 To Len(vC)
                If Mid(vC, vN2, 1) Like "[a-z]" Then _
                    vC.Interior.Color = RGB(255, 150, 255)
                    GoTo EX
            Next vN2
EX:     Next vC
    End With
   
End Sub
Thank you so much. It helped a lot!
 
Upvote 0
Sorry, after Peter's comment I notice that I forgot to close "If" statement.
Of course, with suppose OP asks to highlight cells that contain any lowercase letter.
VBA Code:
       If Mid(vC, vN2, 1) Like "[a-z]" Then
           vC.Interior.Color = RGB(255, 150, 255)
           GoTo EX
       End If
 
Upvote 0
suppose OP asks to highlight cells that contain any lowercase letter.
If that is the case, then I think another (non-looping) way would be

VBA Code:
Sub AnyLowerCase()
  With Range("table").CurrentRegion
    .FormatConditions.Add Type:=xlExpression, Formula1:=Replace("=NOT(EXACT(#,UPPER(#)))", "#", .Cells(1).Address(0, 0))
    .FormatConditions(1).Interior.Color = RGB(255, 150, 255)
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,826
Members
449,190
Latest member
rscraig11

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