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!
 

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

didIDo_that

New Member
Joined
Jul 30, 2010
Messages
24
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
 

alvinwlh

Active Member
Joined
Feb 16, 2009
Messages
305
Can also try:

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

Watch MrExcel Video

Forum statistics

Threads
1,123,052
Messages
5,599,511
Members
414,315
Latest member
Yolanda5050

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
Top