VBA subtract from next column above cell

Prabhudharun

New Member
Joined
Feb 22, 2018
Messages
7
[TABLE="class: outer_border, width: 300, align: center"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]c[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]5000[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]300[/TD]
[TD]4700[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]500[/TD]
[TD]4200[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]600[/TD]
[TD]3600[/TD]
[/TR]
</tbody>[/TABLE]

Hi Team,
I have a sheet like above.

I need to subtract B2 from c1, B3 from C2, B4 from C3 till last row of B.

Need a vba code. Can some one help me on this.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try this:
Code:
Sub MyMacro()

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

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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