ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Copy Sum formulat to another row (https://www.excelbanter.com/excel-worksheet-functions/183086-copy-sum-formulat-another-row.html)

Excel Curious

Copy Sum formulat to another row
 
I want to copy a SUM formula from a row that is summing 4 rows of data to
another row where I need it to copy 3 rows of data or 5 rows of data. Is
there a way for the SUM formula to "auto size"?

ryguy7272

Copy Sum formulat to another row
 
Try this:
Sub ProcessData()
Dim LastRow As Long
Dim LastCol As Long

With ActiveSheet

LastRow = .Cells(.Rows.count, "A").End(xlUp).Row
LastCol = .Cells(1, .Columns.count).End(xlToLeft).Column
..Cells(LastRow + 1, "A").Resize(, LastCol).Formula = "=Sum(A1:A" & LastRow &
")"
End With

End Sub

Regards,
Ryan---

--
RyGuy


"Excel Curious" wrote:

I want to copy a SUM formula from a row that is summing 4 rows of data to
another row where I need it to copy 3 rows of data or 5 rows of data. Is
there a way for the SUM formula to "auto size"?


Excel Curious

Copy Sum formula to another row
 
Is there a formula that can accomplish this rather than VBA?

What I want to do is very similar to a subtotal, but without any common item
to subtotal by.

EXAMPLE:
1] 7
2] 5
3] 6
4] <SUM formula here for rows 1-3 RESULT 18
5] 2
6] 8
7] <copy above formula from 4, but have SUM rows 5-6 RESULT 10
8] 3
9] <copy above formula from 4, but have SUM row 8 RESULT 3





"ryguy7272" wrote:

Try this:
Sub ProcessData()
Dim LastRow As Long
Dim LastCol As Long

With ActiveSheet

LastRow = .Cells(.Rows.count, "A").End(xlUp).Row
LastCol = .Cells(1, .Columns.count).End(xlToLeft).Column
.Cells(LastRow + 1, "A").Resize(, LastCol).Formula = "=Sum(A1:A" & LastRow &
")"
End With

End Sub

Regards,
Ryan---

--
RyGuy




All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com