Using If Statement to avoid a #Div/0!

dancushing

New Member
Joined
Dec 28, 2005
Messages
3
I am trying to add this formula to my worksheet using VBA.

=IF(E5<=0,"",(E4/E5)*100)

I tried to use this line to do this.

Range("E6").Formula = "=IF(E5<=0,"",(E4/E5)*100)"

I get a 1004 error when I try to run this and I think it has something to do with the quotation marks in the middle of the statement.

I am using this formula in this cell because this cell is part of another formula that computes an average. If there is a #Div/0! then my other formula doesn't work right.

Is there any way to enter this formula using VBA?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I can't open Excel at the moment, but have you tried typing the formula into a cell with the macro recorder running and seeing what code it writes for you?
 
Upvote 0
Didn't even think of that. It was getting late when I posted this question. I just tried your suggestion and it recorded it in R1C1 style. It appears to work so I will try to use it that way. Once I get it working right I will post a reply with the fixed code. Thanks!
 
Upvote 0
Again from memory, but I seem to recall a button on the toolbar that appears when you're recording a macro, that changes from relative to absolute references if you'd prefer absolute in your formula.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top