Clearing cells that only contain spaces

R

Rodrigo Ayres

Hi all!

Can anyone tell me how to write code to remove any number of spaces from cells that ONLY contain spaces?

Thank you!

Rodrigo
 
T

Tom Ogilvy

Dim rng as Range, cell as Range
On Error Resume Next
set rng = ActiveSheet.UsedRange.SpecialCells(xlconstants,xlTextValues)
On Error goto 0
for each cell in rng
if len(trim(cell.Value)) = 0 then
cell.Clearcontents
end if
Next

--
Regards,
Tom Ogilvy


Rodrigo Ayres said:
Hi all!

Can anyone tell me how to write code to remove any number of spaces from
cells that ONLY contain spaces?
 
Top