VBA: Multiplying columns into new column

JetSetDrive

New Member
Joined
Jul 26, 2019
Messages
14
I need a VBA code that will multiple column A*B and insert it into column C.

Range(C:C).Formulat = "A1*B1

The reason this code is tricky for me is because the code will be ran on worksheets with varying amounts of rows, so it needs to only be ran for active rows.

The data also has a header, if I have to put the data back later it is not a big deal.

I appreciate the help. I have spent too long trying to figure this out.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome to the Board!

Try this code:
Code:
Sub MyMacro()

    Dim lr As Long
    
'   Find last row with data in column B
    lr = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Populate formulas in column C from row 2 to last row
    Range("C2:C" & lr).FormulaR1C1 = "=RC[-2]*RC[-1]"

End Sub
 
Upvote 0
Hi & welcome to MrExcel
How about
Code:
   Range("C2", Range("A" & Rows.Count).End(xlUp).Offset(, 2)).Formula = "=A2*B2"
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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