Add a Total Row to the bottom where the number of rows will be a variable

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I have data starting from Row 8. The Last row # will be different each time.

After I run my code, which puts formulas down Column F I want to find the last row and in the next one put a formula that sums column F (Column F values will always start in Row 8)

So If I have data running from F8 down to F26 (which will always change - could be F32 the next time) I want to put a formula in F27 that sums From F8 down to F26.

Is this Possible?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Code:
Dim LastRow As Long

LastRow = Cells(Rows.Count, 6).End(xlUp).Row


Cells(LastRow, 6).Offset(1).Formula = "=SUM(F8:F" & LastRow & ")"
 
Last edited:
Upvote 0
Thanks My friend!

What if I wanted to format that cell with a double underline? Is it possible to format?
 
Upvote 0
Try this:

Code:
Dim LastRow As Long

LastRow = Cells(Rows.Count, 6).End(xlUp).Row


With Cells(LastRow, 6).Offset(1)
    .Formula = "=SUM(F8:F" & LastRow & ")"
    .Borders(xlEdgeBottom).LineStyle = xlDouble
End With
 
Upvote 0
What if I wanted a Sumif instead of Sum?

LastRow = Cells(Rows.Count, 2).End(xlUp).Row
'
With Cells(LastRow, 6).Offset(1)
.Formula = "=SUMIF(C8:C" & LastRow & ","Child",F8:F" & LastRow & ")"
.Borders(xlEdgeBottom).LineStyle = xlDouble
.Borders(xlEdgeTop).LineStyle = xlContinuous
End With

Obviously, it doesn't like my formula.
 
Upvote 0
Try changing this:
Code:
.Formula = "=SUMIF(C8:C" & LastRow & ","Child",F8:F" & LastRow & ")"
to this:
Code:
.Formula = "=SUMIF(C8:C" & LastRow & ", ""Child"" ,F8:F" & LastRow & ")"
 
Upvote 0
Sorry for delayed response. That worked perfectly.

THANK YOU
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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