Border & Sum

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top