Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function to know if #DIV/0 error in the cell 1

Status
Not open for further replies.

Ranf

Technical User
May 1, 2003
6
IL
which function in VBA can tell me that a cell has a #DIV/0 error so I could change its value to ""?
(Say something like "if (cells(1,1).XXX) then cells.value="")
I guess it's elementary but I'm on this one for the whole afternoon ... :(
 
Well, you could use this:
[blue]
Code:
  If [C1].Text = "#DIV/0!" Then [C1] = "0"
[/color]

But of course that destroys whatever formula you had in the cell ("C1" in this example) by replacing it with a constant zero. That may be ok if your macro code is putting the formula there in the first place.

However, you would be better off not using VBA, but rather using a formula like this:
[blue]
Code:
  =IF(B1,A1/B1,0)
[/color]

so that when "B1" is zero the result is zero otherwise the result is the quotient.
 
Genius is in Simplicity
10x so much,
Made my *life* much more fluent :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top