ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Border & Sum (https://www.excelbanter.com/excel-programming/319858-border-sum.html)

Teresa

Border & Sum
 
Hi, I have lines of data which vary dynamically, i.e. could be 5,7,11 lines
etc.

At the bottom of the last line, I always need a border and a Sum Amount,
help is greatly appreciated

David

Border & Sum
 
Hi,
This puts a border above and below the cell you are on.
Sub Macro1()
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub


"teresa" wrote:

Hi, I have lines of data which vary dynamically, i.e. could be 5,7,11 lines
etc.

At the bottom of the last line, I always need a border and a Sum Amount,
help is greatly appreciated


Claud Balls

Border & Sum
 
This should do the trick:

Option Explicit
Sub get_total()
Dim intNumRows As Integer, c As Variant, lngCellTotal As Long
intNumRows = Cells(50, "A").End(xlUp).Row
With Range("A" & intNumRows + 1)
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeRight).Weight = xlMedium
End With
For Each c In Range("A1", "A" & intNumRows)
lngCellTotal = lngCellTotal + c.Value
Next
Range("A" & intNumRows + 1) = lngCellTotal

End Sub



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tom Ogilvy

Border & Sum
 
Here is a slightly different interpretation. Change A to reflect the column
containing the data:

Sub get_total()
Dim rng As Range
Dim intNumRows As Integer, c As Variant, _
lngCellTotal As Long
intNumRows = Cells(50, "A").End(xlUp).Row
With Range("A" & intNumRows + 1)
.Borders(xlEdgeTop).Weight = xlMedium
Set rng = Range("A1", "A" & intNumRows)
.Formula = "=Sum(" & rng.Address & ")"
End With
End Sub

--
Regards,
Tom Ogilvy

"Claud Balls" wrote in message
...
This should do the trick:

Option Explicit
Sub get_total()
Dim intNumRows As Integer, c As Variant, lngCellTotal As Long
intNumRows = Cells(50, "A").End(xlUp).Row
With Range("A" & intNumRows + 1)
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeRight).Weight = xlMedium
End With
For Each c In Range("A1", "A" & intNumRows)
lngCellTotal = lngCellTotal + c.Value
Next
Range("A" & intNumRows + 1) = lngCellTotal

End Sub



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





All times are GMT +1. The time now is 01:58 AM.

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