How to use an IF formula in VBA

lmichaluk

New Member
Joined
Aug 4, 2011
Messages
9
Hi there - very new to excel and trying to write a macro that will sum the cells above and then will not let the answer exceed a given amount. For example: the "sum macro" would be something like
Sub b8()
Range("b8").Formula = "=b6+b7"
End Sub

The "If" statement would be something like =IF(B8<100.1,B8,100)

So. How do I include the If statement in the macro?
Thanks
 
I don't have any subs named, although when I pasted the info provided and hit "run" (from the ribbon), I get a window up that names the macro "Sheet4.b13" which is the cell in which the macro is placed. Then when I hit "run" on that menu, I get the same "compile" error message. This happens when I manually replace the 1 with an l as well. I do note that when I put the l into my excel sheet, it displays as a 1 - this happens throughout the sheet.
If need be, I will just add several rows to the sheet, and include all the cell numbers (i.e. long hand way of doing the calc)...not terribly elegant, but seems to work.
I apppreciate your help on this.
Cheers
Linda
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,224,600
Messages
6,179,835
Members
452,947
Latest member
Gerry_F

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