Avatar of Peter Groves
Peter Groves
 asked on

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

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
VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Rob Henson

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
byundt

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Peter Groves

ASKER
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
SOLUTION
Wayne Taylor (webtubbs)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Peter Groves

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

Pete
Rob Henson

Formula can be simpler as well:

=IFERROR(AX3/AC3,NA())
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23