If you would like to clean an entire sheet of its contents (withou
removing formatting) use the ClearContents method, otherwise use th
delete method. Here is an example:
Sub ClearActiveSheet ()
Application.ScreenUpdating=False ' lets code execute faster
The use of the CLEAN Worksheet Function to remove unprintable characters
will only remove CHAR(0) through CHAR(31), Char(129), Char(141), Char(143),
and Char(144). It will have no effect on Char(160).
When you apply the function to all cells in a workbook you would wipe out
formulas; remove linebreaks closing up words that won't even have a space
between them.
I want to remove ANY characters there are not alphanumeric (not to include
spaces or hyphens, I still need those). These cells will not have formulas
at the time I'm cleaning up the cells. Since I pull from different
databases, I run into a problem when I compare the cell values - which I need
to do from the right. If there is a character that takes a space they won't
match and because this character is not appearing in every cell or even in
every column I can't just say ignore the first right character.
Sub CleanCells()
Dim sStr as String
Dim cell as Range
for each cell in selection
if not cell.hasFormla then
sStr = Application.Substitute(cell.value,chr(160)," ")
sStr = Application.Clean(sStr)
sStr = Application.Trim(sStr)
cell.Value = sStr
end if
Next
End Sub
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.