Use VBA to compute mathematics formula

mpham168

New Member
Joined
Jul 21, 2011
Messages
7
So I've got a formula computing some values...

basically if
cell column J has <1.5 Million then 5% x column J
cell column J has >=1.5 Million but <3 Million then 10% x column J
cell column J has >=3 Million but <10 Million then 15% x column J
cell column J has >=10 Million then 20% x column J

I know I can use the below formula... and fill the column BUT I would rather have it be computed and just a value returned.

=IF(J2>=10000000,ROUNDDOWN(J2*0.2,1),IF(AND(J2>=3000000,J2<10000000),ROUNDDOWN(J2*0.15,1),IF(AND(J2>=1500000,J2<3000000),ROUNDDOWN(J2*0.1,1),IF(J2<1500000,ROUNDDOWN(J2*0.05,1)))))
Thanks

mpham
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi mpham,

I don't know of a formula to do this that doesn't require any IF functions, but here is a simpler formula than the one you have:

=IF(J2<1500000,0.05,IF(J2<3000000,0.1,IF(J2<10000000,0.15,0.2)))*J2

Damon
 
Upvote 0
So which column do you want the result in ??
 
Upvote 0
I have to duck out for a while, so I've taken a guess that the formula goes in column "K", if that's incorrect, change the column reference in line 4
Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "J").End(xlUp).Row
    With Range("K1:K" & lr) 'change col reference to suit
        .Formula = "=IF(J2<1500000,0.05,IF(J2<3000000,0.1,IF(J2<10000000,0.15,0.2)))*J2"
        .Value = .Value
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
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