ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Summary in the last row (https://www.excelbanter.com/excel-programming/438375-summary-last-row.html)

Mia

Summary in the last row
 
Hi,

I'm need to make a vba macro where the macro automaticly shall find
the last row and make a summary of the total column D. I cant get
It right, can someone please help?

So far I only has typed following.

Dim lngLastRow As Long
lngLastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & lngLastRow + 1) = _

--
Best regards
Mia

Don Guillett

Summary in the last row
 
Sub slr()
dim mc as long
Dim lr As Long
mc = 4 'col D
lr = Cells(Rows.Count, mc).End(xlUp).Row
Cells(lr + 1, mc) = _
Application.Sum(Range(Cells(1, mc), Cells(lr, mc)))
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mia" wrote in message
...
Hi,

I'm need to make a vba macro where the macro automaticly shall find
the last row and make a summary of the total column D. I cant get
It right, can someone please help?

So far I only has typed following.

Dim lngLastRow As Long
lngLastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & lngLastRow + 1) = _

--
Best regards
Mia



Ryan H

Summary in the last row
 
You can use this code. I assume Col. D has a header row so the code will
insert the SUM function in the cell below the last row with data in Col. D.
Plus, you don't have to reference the ActiveSheet, in VBA it is assumed you
mean the ActiveSheet. Hope this helps! If so, let me know, click "YES"
below.

Dim lngLastRow As Long

' find last row with data in Col.D
lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

' insert sum formula
Cells(lngLastRow + 1, "D").Formula = "=SUM(D2:D" & lngLastRow & ")"

--
Cheers,
Ryan


"Mia" wrote:

Hi,

I'm need to make a vba macro where the macro automaticly shall find
the last row and make a summary of the total column D. I cant get
It right, can someone please help?

So far I only has typed following.

Dim lngLastRow As Long
lngLastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & lngLastRow + 1) = _

--
Best regards
Mia


Mia

Summary in the last row
 
Thank you!

It works perfekt!!!!

--
Best regards
Mia


"Don Guillett" skrev:

Sub slr()
dim mc as long
Dim lr As Long
mc = 4 'col D
lr = Cells(Rows.Count, mc).End(xlUp).Row
Cells(lr + 1, mc) = _
Application.Sum(Range(Cells(1, mc), Cells(lr, mc)))
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mia" wrote in message
...
Hi,

I'm need to make a vba macro where the macro automaticly shall find
the last row and make a summary of the total column D. I cant get
It right, can someone please help?

So far I only has typed following.

Dim lngLastRow As Long
lngLastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & lngLastRow + 1) = _

--
Best regards
Mia


.


Mia

Summary in the last row
 
Hi again,

Thank you again for your help before.

If I want the answer (the sum) to be in a special format, what shall
I write? I want it to be bold and in curency (swedish kronor).
Do you know how to code this?


--
Best regards
Mia


"Don Guillett" skrev:

Sub slr()
dim mc as long
Dim lr As Long
mc = 4 'col D
lr = Cells(Rows.Count, mc).End(xlUp).Row
Cells(lr + 1, mc) = _
Application.Sum(Range(Cells(1, mc), Cells(lr, mc)))
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mia" wrote in message
...
Hi,

I'm need to make a vba macro where the macro automaticly shall find
the last row and make a summary of the total column D. I cant get
It right, can someone please help?

So far I only has typed following.

Dim lngLastRow As Long
lngLastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & lngLastRow + 1) = _

--
Best regards
Mia


.


Ryan H

Summary in the last row
 
You would have to change properties on the Font collection.

Dim lngLastRow As Long

' find last row with data in Col.D
lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

' insert sum formula
With Cells(lngLastRow + 1, "D")
.Formula = "=SUM(D2:D" & lngLastRow & ")"
.Font.Bold = True
.Font.Name = "Arial"
.NumberFormat = "$#,##0.00"
End With

Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"Mia" wrote:

Hi again,

Thank you again for your help before.

If I want the answer (the sum) to be in a special format, what shall
I write? I want it to be bold and in curency (swedish kronor).
Do you know how to code this?


--
Best regards
Mia


"Don Guillett" skrev:

Sub slr()
dim mc as long
Dim lr As Long
mc = 4 'col D
lr = Cells(Rows.Count, mc).End(xlUp).Row
Cells(lr + 1, mc) = _
Application.Sum(Range(Cells(1, mc), Cells(lr, mc)))
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mia" wrote in message
...
Hi,

I'm need to make a vba macro where the macro automaticly shall find
the last row and make a summary of the total column D. I cant get
It right, can someone please help?

So far I only has typed following.

Dim lngLastRow As Long
lngLastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & lngLastRow + 1) = _

--
Best regards
Mia


.



All times are GMT +1. The time now is 02:57 PM.

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