Delete all cell data that is not all CAPS

overbet

Board Regular
Joined
Jul 9, 2010
Messages
63
Office Version
  1. 2010
Does anyone know how to delete all cell data that is not all CAPS and leave everything that is all CAPS? Ive tried these two pieces of code I found online, but neither works. The first clears everything and the second deletes the blank rows only. Thanks

Code:
Sub Delete_Cells_Without_Caps()


Dim k As Long


For k = 1 To 50000


     '   If Worksheets("junk").Cells(k, "b").Value <> "Caps" Then
        Worksheets("junk").Cells(k, "a").ClearContents
      '  End If
Next
End Sub

Code:
Sub Delete_Cells_Without_Caps()
For i = 50000 To 1 Step -1
If Range("A" & i).Value = LCase(Range("A" & i).Value) Then
Range("A" & i).EntireRow.Delete
End If
Next i
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try changing
Code:
If Range("A" & i).Value = LCase(Range("A" & i).Value) Then
to
Code:
If Range("A" & i).Value <> UCase(Range("A" & i).Value) Then
 
Upvote 0
Select the cells you want to apply this to first, then run this macro.
Code:
Sub ClearIfNotAllCaps()
'select cells first, then run this macro
Dim c As Range
Application.ScreenUpdating = False
For Each c In Selection
    If UCase(c.Value) <> c.Value Then c.ClearContents
Next c
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you both. Joe, your code works amazing. Fast and perfect. Thank you very much for your help and time. Cheers
 
Upvote 0
Does anyone know how to delete all cell data that is not all CAPS and leave everything that is all CAPS? Ive tried these two pieces of code I found online, but neither works. The first clears everything and the second deletes the blank rows only.
Your question is open to some interpretation. For example, you code is testing against the text "Caps" which leads one to wonder if you meant the text "CAPS" or is CAPS was meant as all uppercase characters. If you did mean all uppercase characters, then letters are obvious, but what about numbers and punctuation marks... their lowercase and uppercase representations are identical, so some would say they are all caps as well (for example, AB.CD or XYZ123... would they be considered all caps?). Please clarify.
 
Upvote 0
Hi Rick, sorry about that. I did me all CAPS (capital/upper case letters). Thank you for pointing that out. I will try to be more clear next time. Regards
 
Upvote 0
Select the cells you want to apply this to first, then run this macro.
Code:
Sub ClearIfNotAllCaps()
'select cells first, then run this macro
Dim c As Range
Application.ScreenUpdating = False
For Each c In Selection
    If UCase(c.Value) <> c.Value Then c.ClearContents
Next c
Application.ScreenUpdating = True
End Sub
If I am not mistaken, I believe this one-liner will do the same thing as your code does...
Code:
[table="width: 500"]
[tr]
	[td]Sub ClearIfNotAllCaps()
  Selection = Evaluate(Replace("IF(EXACT(@,UPPER(@)),@,"""")", "@", Selection.Address))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
If I am not mistaken, I believe this one-liner will do the same thing as your code does...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub ClearIfNotAllCaps()
  Selection = Evaluate(Replace("IF(EXACT(@,UPPER(@)),@,"""")", "@", Selection.Address))
End Sub[/TD]
[/TR]
</tbody>[/TABLE]
Nice!
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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