Trouble inserting formula =IF(OR(ISNUMBER(AC3)=FALSE,AC3=0);0;AX3/AC3) into excel column via VBA

Peter Groves
Peter Groves used Ask the Experts™
on
Having trouble inserting a formula into excel from access 2013 VBA.
this formula works if I put it directly in Excel

IF(OR(ISNUMBER(AC3)=FALSE;AC3=0);'N/A';AX3/AC3)

but when I try to put it there via VBA I've exhausted my tries!

With wks

  .UsedRange 'Refresh UsedRange
  Lastrow = .UsedRange.rows(.UsedRange.rows.Count).Row

this works (but with a ton of divide by zero errors!

  .Range("BG3:BG" & Lastrow).Formula = "=AX3/AC3)"


This is what I want
.Range("BG3:BG" & LastRow).Formula = "=IF(OR(ISNUMBER(AC3)=FALSE;AC3=0);"N/A";AX3/AC3)"

I expect I'd need to get the quotation marks right!  

I also tried things like
.Range("BG3:BG" & Lastrow).Formula = "=IF(OR(ISNUMBER(AC3)=FALSE,AC3=0);0;AX3/AC3)"
trying to eliminate the need for quotation modification just to see if that works!  I could live with it if it did!  But same error
application defined or object defined error 1004

Thankls

Pete
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mechanical Engineer
Most Valuable Expert 2013
Top Expert 2013
Commented:
Try using commas instead of semicolons as the list separator. Range.Formula expects U.S. standard function names, list separators and date formats.

.Range.FormulaLocal ought to accept your formula as written.

Author

Commented:
Works , but in excel they show up as semicolons, which is why I didn't try them!    Now , would ya have a suggestion to get the "N/A" in there?

IF(OR(ISNUMBER(AC3)=FALSE;AC3=0);"N/A";AX3/AC3)

Pete
You can use the NA() function to return the #N/A error...

IF(OR(ISNUMBER(AC3)=FALSE;AC3=0);NA();AX3/AC3)

If you needed to return a string, use double quotation marks...

IF(OR(ISNUMBER(AC3)=FALSE;AC3=0);""N/A"";AX3/AC3)

Author

Commented:
Thanks guys!  I should have asked sooner!  Burned several hours on this!

Pete
Rob HensonFinance Analyst

Commented:
Formula can be simpler as well:

=IFERROR(AX3/AC3,NA())

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial