Need help converting formula to VBA...

Lidsavr

Active Member
Joined
Jan 10, 2008
Messages
330
I am writing code for Excel 2003

I am stuck on converting a formula to the VBA equivalent. The formula is:

=SUMIF(AB4:AD4,">10")/MAX(1,COUNTIF(AB4:AD4,">10"))

This formula works great in a cell on the spreadsheet!


In attempting to write the code, I've tried:

Code:
ActiveCell.Formula = "=SUMIF(AB4:AD4,">10")/MAX(1,COUNTIF(AB4:AD4,">10"))

However, I get a compile error: 'Expected End of Statement' at the first quotation mark after the range.

I've also tried writing the VBA equivalent, but get stuck on the correct syntax.

Can anyone help me convert this formula to code?

Thank you,

Charles
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try

Code:
x = Evaluate("SUMIF(AB4:AD4,"">10"")/MAX(1,COUNTIF(AB4:AD4,"">10""))")
 
Upvote 0
Code:
ActiveCell.Formula = "=SUMIF(AB4:AD4,"">10"")/MAX(1,COUNTIF(AB4:AD4,"">10""))"

Note that unless you have a specific reason for using ActiveCell, you don't need to select ranges to work with them in VBA, you can work with ranges directly:

Code:
Range("A3").Formula = "=SUMIF(AB4:AD4,"">10"")/MAX(1,COUNTIF(AB4:AD4,"">10""))"
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

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