check cells before division by zero
I want to make sure of no divison by zero error messages
I am doing division on a mshflexgrid like this:
with grid
.textmatrix(2, 12) = .textmatrix(2, 11) / .textmatrix(2, 9)
some of the cells maybe empty and some maybe formated as currency with a dollar sign
is this the best method:
vb Code:
If val(.textmatrix(2, 11) <> 0 then
If val(.textmatrix(2, 9) <> 0 then
.textmatrix(2, 12) = .textmatrix(2, 11) / .textmatrix(2, 9)
else
textmatrix(2, 12) = ""
end if
end if
would this code be appropriate?
Re: check cells before division by zero
Quote:
Originally Posted by isnoend07
would this code be appropriate?
It looks Ok. Does it work? Are you havinga problem?
Re: check cells before division by zero
Quote:
Originally Posted by Hack
It looks Ok. Does it work? Are you havinga problem?
Yes i am having having a problem, but i am not sure if this is it.
I have a huge program with about 50 of these. It has gotton very hard to
debug. Many are if this chbox is checked then divide by this cell if not divide by this cell etc, etc....
Re: check cells before division by zero
Quote:
Originally Posted by isnoend07
Yes i am having having a problem, but i am not sure if this is it.
I have a huge program with about 50 of these. It has gotton very hard to
debug. Many are if this chbox is checked then divide by this cell if not divide by this cell etc, etc....
After experimenting i have found this code will fail if val(contents) is formatted as currency. It will return 0 even though it contains a valid number
Re: check cells before division by zero
Consider using the INSTR function to determine if any number other than zero exists in the cell string. If it does, you can then next pinpoint the starting position of the first non-zero integer and determine the value of the midstring using Val from that point on.
It's rather amazing what we have to do sometimes to evaluate strings. :sick:
Re: check cells before division by zero
Quote:
Originally Posted by Edwin Hackleman
Consider using the INSTR function to determine if any number other than zero exists in the cell string. If it does, you can then next pinpoint the starting position of the first non-zero integer and determine the value of the midstring using Val from that point on.
It's rather amazing what we have to do sometimes to evaluate strings. :sick:
I have decided to use currency only for totals and not subtotals. Saves a lot of ifs