Validate data part 2

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The coding given by Dave works fine. it traps erros as a whoel in the range.
However...

I have a problem with null values, cells in range can have null values, null
values are OK. I want so search each cell in the range then if its contents
is null replace it with zero. Something like:

define range

for each cell in range
if value is null then
value = 0
end if

I do not know how to loop through the cells in the range.

Thanx again.
 
dim myCell as range
dim myRng as range
set myrng = worksheets("sheet999").range("a1:D9")

for each mycell in myrng.cells
if isempty(mycell.value) then
mycell.value = 0
end if
next mycell

or to get them all at once...

dim myRng as range
set myrng = worksheets("sheet999").range("a1:D9")
on error resume next
myrng.cells.specialcells(xlcelltypeblanks).value = 0
 
You are the Man. Thanx

Dave Peterson said:
dim myCell as range
dim myRng as range
set myrng = worksheets("sheet999").range("a1:D9")

for each mycell in myrng.cells
if isempty(mycell.value) then
mycell.value = 0
end if
next mycell

or to get them all at once...

dim myRng as range
set myrng = worksheets("sheet999").range("a1:D9")
on error resume next
myrng.cells.specialcells(xlcelltypeblanks).value = 0
 

Ask a Question

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.

Ask a Question

Back
Top