View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Sub to clear cells with zeros or null strings within a selecte

Sub MaxSingapore()
Set rng = Selection
For Each ar In Selection.Areas
For Each itm In ar
If Trim(itm.Value) = "" Or itm.Value = 0 Then itm.Clear
Next 'itm
Next 'ar
End Sub
--
Jay


"Max" wrote:

Thanks, Jay. But I want the sub to clear such cells (ie like CTRL-selecting
these cells at one go, then pressing the Delete key), not set these cells to
"". How would your sub then look like ? The selected range may contain cells
with "" and cells with zeros.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---
"Jay" wrote:
Hi Max -

Although VBA variables can evaluate to "Null", worksheet cells cannot. A
cell is considered empty if it evaluates to a zero-length string (zls),
designated as "". So the procedure below sets cells in the selection to ""
if they containing a zero or spaces only.

Sub MaxSingapore()
Set rng = Selection
For Each itm In rng
If Trim(itm.Value) = "" Or itm.Value = 0 Then itm.Value = ""
Next 'itm
End Sub
--
Jay