Autosum Range and posting results in another sheet on the same workbook

DiogoCuba

New Member
Joined
Mar 15, 2014
Messages
10
Hello, Masters!

I need your help to get a code for a report I receive every month.

In this report on column CU I have all costs of a certain product and I need to sum them up from cell CU8 until the last row with data; Then I need to get the result of that sum to another sheet named "Hotel Costs" on cell B2.

I have came up to this so far, but it only sum the CU8 to the last row, but I cannot figure out how to copy that to the other sheet:

Sheets("Hotel").Activate
Range("CU" & Rows.Count).End(xlUp).Offset(2, 0).FormulaR1C1 = "=SUM(R8C:R[-2]C)"
LastRow = Cells(Rows.Count, 1).End(xlUp).Row

Please keep in mind that the report will never have a fixed last row.

If there is another way to do that I am happy to use it as well!

Thanks!
 

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.
Try:
Code:
Sub Test()
    Application.ScreenUpdating = False
    Dim bottomCU As Long
    bottomCU = Range("CU" & Rows.Count).End(xlUp).Row
    Range("CU" & bottomCU + 1).Formula = "=sum(CU8:CU" & bottomCU & ")"
    Range("CU" & bottomCU + 1).Copy
    Sheets("Hotel Costs").Range("B2").PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
Code:
Sub Test()
    Application.ScreenUpdating = False
    Dim bottomCU As Long
    bottomCU = Range("CU" & Rows.Count).End(xlUp).Row
    Range("CU" & bottomCU + 1).Formula = "=sum(CU8:CU" & bottomCU & ")"
    Range("CU" & bottomCU + 1).Copy
    Sheets("Hotel Costs").Range("B2").PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub

Thanks mumps, but I have just tried and it returned 0 on the spreadsheet. Any ideas why?
In addition, I have review the format of the cells on the range CU and they are all formatted as numbers.
 
Upvote 0
Thanks mumps, but I have just tried and it returned 0 on the spreadsheet. Any ideas why?
In addition, I have review the format of the cells on the range CU and they are all formatted as numbers.

I think I realized that I was missing to active the worksheet where the code should run! It's running perfect now!

Thank you very much for your time and work!
 
Upvote 0
I think I realized that I was missing to active the worksheet where the code should run!
For this problem you shouldn't need to do that, though it isn't really a problem if you want to.

I don't know what that sheet name is, so I've used the name "Data" in my alternative code below.
If you want to give it a try in a copy of your workbook, just edit "Data" to the name of the sheet where you are trying to sum column CU.
Rich (BB code):
Sub Total_CU()
  With Sheets("Data").Range("CU" & Rows.Count).End(xlUp).Offset(1)
    .FormulaR1C1 = "=SUM(R8C:R[-1]C)"
    Sheets("Hotel Costs").Range("B2").Value = .Value
  End With
End Sub
 
Upvote 0
For this problem you shouldn't need to do that, though it isn't really a problem if you want to.

I don't know what that sheet name is, so I've used the name "Data" in my alternative code below.
If you want to give it a try in a copy of your workbook, just edit "Data" to the name of the sheet where you are trying to sum column CU.
Rich (BB code):
Sub Total_CU()
  With Sheets("Data").Range("CU" & Rows.Count).End(xlUp).Offset(1)
    .FormulaR1C1 = "=SUM(R8C:R[-1]C)"
    Sheets("Hotel Costs").Range("B2").Value = .Value
  End With
End Sub

Peter_SSs the VB you offered is simpler then the one mumps wrote and also works great!
Thanks for your time and work!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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