We help IT Professionals succeed at work.

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

87 Views
Last Modified: 2018-12-03
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

Mechanical Engineer
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

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
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

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

Pete
Rob HensonFinance Analyst
CERTIFIED EXPERT

Commented:
Formula can be simpler as well:

=IFERROR(AX3/AC3,NA())

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions