add/subtract last rows in columns

Fyr

Active Member
Joined
Jan 20, 2009
Messages
375
I have this scenario.
I'm looking up the last row in column C with this:
Code:
Range("C6").Value = Sheets("table").Cells(65536, "C").End(xlUp).Value

Here's the problem with this scenario.
I want to add and subtract the last rows in columns C, D, E, and F in this order: D - C + F - E,
and then place them in sheet1 in cell D6.

Is this possible?

Thanks for taking a look!
 

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.
Try

Code:
Dim a, b, c, d, e
With Sheets("table")
    a = .Cells(Rows.Count, "D").End(xlUp).Value
    b = .Cells(Rows.Count, "C").End(xlUp).Value
    c = .Cells(Rows.Count, "F").End(xlUp).Value
    d = .Cells(Rows.Count, "E").End(xlUp).Value
End With
Sheets("Sheet1").Range("D6").Value = a - b + c - d
 
Upvote 0
Hi fyr,

You could try

Sub test()
with sheets("table")
c = .Cells(65536, "C").End(xlUp).Value
d = .Cells(65536, "D").End(xlUp).Value
e = .Cells(65536, "E").End(xlUp).Value
f = .Cells(65536, "F").End(xlUp).Value
Range("C6").Value = c - d + e - f
End Sub

Sorry - just saw Vog's post!
 
Last edited:
Upvote 0
Fyr

Tables often have the same number of rows in each column. I don't know what yours is like, but if that is the case with your table on the 'table' sheet, then you could try this.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Last_Row_Calculation()<br>    <SPAN style="color:#00007F">With</SPAN> Sheets("table").Range("C" & Rows.Count).End(xlUp)<br>        Sheets("Sheet1").Range("D6").Value = _<br>            .Offset(, 1).Value - .Value + .Offset(, 3).Value - .Offset(, 2).Value<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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