VBA for inserting product formula in column cells

jchungusc

New Member
Joined
Nov 28, 2011
Messages
2
Hello,

Thanks in advance for any help!

I need to create a macro for inserting a simple product formula in all cells with data adjacent to that cell. I want the macro to insert "=product(G1*I1)" in H1, "=product(G2*I2)" in H2 and so on, down the column until it reaches a cell where no data exists in the cell adjacent to Hx.

Thanks!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I'm assuming that there are no blanks from cell G1 down to where you want to stop inserting the formula.

sub ProdFormu()

ActiveSheet.Range("H1").Formula = "=product(G1*I1)"
ActiveSheet.Range("G1").End(xlDown).Select
ActiveSheet.Range("H1",Selection.Offset(0,1)).Filldown

End Sub
 
Upvote 0
Can also try:

Code:
Range("H1:H" & Range("G" & Rows.count).End(xlUp).Row).FormulaR1C1 = "=PRODUCT(RC[-1]*RC[1])"
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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