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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2003 isEMPTY is causing DIV/0 error 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I have a vba script that is causing a DIV/0 error. I have tried different approaches with no success. I am hoping to get some assistance. If I go on the spreadsheet and use the formula =IF(E6=0,0,E6/D6) this works on the spreadsheet so I tried to put this in a new formula I am now getting a run-time error 1004. application defined or object -defined error. For this example iTRow is 6.

Tom

Code:
'Original code
With goXL.ActiveSheet
'.Cells(iTRow, 6).Formula = "=if(ISBLANK(E" & (iTRow) & "),0,E" & (iTRow) & "/D" & (iTRow) & ")"

'2nd attempt
.Cells(iTRow, 6).Formula = "=if(E" & (iTRow) & "=0" & "),0,E" & (iTRow) & "/D" & (iTRow) & ")"
End with
 
Did you try (iTRow is 6):
[tt]
.Cells(iTRow, 6).Formula = "=if(E" & iTRow & "=0,0,E" & iTRow & "/D" & iTRow & ")"
[/tt]

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Andy,
I just tried your solution and I get the error 1004

Code:
.Cells(iTRow, 6).Formula = "=if(E" & iTRow & "=0" & "),0,E" & iTRow & "/D" & iTRow & ")"
 
Anyway, I'd test D6 instead of E6 as you compute E6/D6 ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I tried to change the formula to iserror and change the cell reference to the denominator I am getting the #DIV/0 error. I will posting the sheet.

Code:
Cells(iTRow, 6).Formula = "=if(ISERROR(D" & (iTRow) & "),0,E" & (iTRow) & "/D" & (iTRow) & ")"
 
Sorry, I don't remember how to attach an excel sheet to this thread.

Tom
 
After much more experimentation I finally got something that works. I get 0 in the cell instead of the DIV/0 error.

I changed the formula to this:

Code:
.Cells(iTRow, 6).Formula = "=if(E" & iTRow & "=0,0,E" & iTRow & "/D" & iTRow & ")"
 
Which is exactly what I gave you.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
You are right Andy. I misread your code.

Tom
 
You do realize the reason why you're getting an error is when the value in Col D is empty or equal to 0, not the value in Col E? Additionally, is there any benefit for you to have the formula in the cell versus the result? Since you are doing this with a macro, the macro could do the calculation and put the results in the cell. Having both the macro & the formula in the cell only makes the spreadsheet bigger (in terms of memory) and may result in taking longer to run the macro or whenever you manipulate your spreadsheet (e.g., it's having to recalculate every formula)
 
Reflects my question, too. Why use VBA at all?

If you were to use the Data > List feature (which has been greatly enhanced in Excel 2007+ versions as the Structured Table feature), Excel will propagate your formulas automatically as you add new rows do data. No VBA required! And I'm a huge VBA fan!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Zelgar,
In this case the manager wants the formula in the spreadsheet.
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top