Clear Contents Of Cell If Value = 0 or Error

G

Guest

I posted last week on this problem I am trying to solve.


Sub stantiate()
Dim myRange As Range
Set myRange = Range("C10:d1000")
For Each c In myRange
If c.Value = 0 Then
c.Value = ""
End If
Next
End Sub

The code gets hung up at:

If c.Value = 0 Then

the cell value could be #N/A or some other
"errors".

Could this be the reason the code gets hung up ?

If so, is there a way to resolve the problem ?

Thank you in advance.
 
G

Guest

If I'm understanding you correctly...if the cell value is actually a cell
error, you would like the cell value=0?
 
S

Susan

you haven't declared c..........

dim c as Range

blah blah
For Each c In myRange
If c.Value = 0 Then
c.Value = ""
End If
Next

also, "Next" needs to be "Next c"
you might also need to change
c.Value = ""
to
c.clearcontents

hope this helps!
susan
 
G

Guest

Thanks for your help.

I need the contents of the cell cleared only if the value = 0.

That said, when I run the macro, some of the cells are #N\A and other error
messages.

I would like the macro to ignore the error messages.
 
R

Rick Rothstein \(MVP - VB\)

Does this code do what you want?

Dim C As Range
Dim myRange As Range
Set myRange = Range("C10:d12")
For Each C In myRange
If Not IsError(C.Value) Then
If C.Value = 0 Then C.cl
End If
Next

Rick
 

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

Similar Threads


Top