In a defined range, clear contents of all cells containg only one character

Zembu

New Member
Joined
Apr 9, 2016
Messages
23
Tazguy37 gave a solution to a slightly different question!

He wrote;

Sub deleteSingles()
Dim cell As Range

On Error Resume Next
For Each cell In Cells.SpecialCells(xlCellTypeConstants)
If Len(cell.Value) = 1 Then cell.Delete
Next cell

End Sub


This solution is almost good for me! I want to (not delete but clear contents) of cells containg a single character, and be able to set a specific range to be operated on.
 
Hi Zembu,

please mind what Fluff has put in: it will kill formulas.

If you care about the time the macro takes maybe try
VBA Code:
Sub ClearContentsSingles_2()
Dim rngCell As Range

Const cstrRange As String = "A2:E50"

With Application
  .ScreenUpdating = False
  .EnableEvents = False
  .Calculation = xlCalculationManual
End With

On Error Resume Next
For Each rngCell In Range(cstrRange).SpecialCells(xlCellTypeConstants)
  If Len(rngCell.Value) = 1 Then rngCell.ClearContents
Next rngCell

With Application
  .ScreenUpdating = True
  .EnableEvents = True
  .Calculation = xlCalculationAutomatic
End With

End Sub
Ciao,
Holger
Hi Holger,
I've now tried both methods and your second one is best for me. For the first, Excel was "not responding" and I gave up after a few hours. I tested both methods this morning on a smaller selection of cells and both worked fine. Then I tried your second on the large selection - as I said 1,365,910 cells and it worked perfectly taking around 5 minutes to finish. PC has only 8GB memory, 64 bit operating system, Windows 7. Many thanks for helping out on this! Cheers, Andrew
 
Upvote 0

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.

Forum statistics

Threads
1,215,474
Messages
6,125,024
Members
449,204
Latest member
LKN2GO

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