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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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