Hi,
I have a dynamic range with column headings (from columns A to R) for which I need to add totals to each columns from L to R. I have the following code which works;
Dim lastRow As Long
lastRow = Cells(Rows.Count, "D").End(xlUp).Row
Cells(lastRow + 3, "L").Formula = "=SUM(L2:L" & lastRow & ")"
Cells(lastRow + 3, "M").Formula = "=SUM(M2:M" & lastRow & ")"
Cells(lastRow + 3, "N").Formula = "=SUM(N2:N" & lastRow & ")"
Cells(lastRow + 3, "O").Formula = "=SUM(O2:O" & lastRow & ")"
Cells(lastRow + 3, "P").Formula = "=SUM(P2:O" & lastRow & ")"
Cells(lastRow + 3, "Q").Formula = "=SUM(Q2:Q" & lastRow & ")"
Cells(lastRow + 3, "R").Formula = "=SUM(R2:R" & lastRow & ")"
I am now trying to get a code that for each of these total numbers in the code above, I want to add a cell border (single line to the top and double line to the bottom). The following code fails in the very first line, can anyone tell me how to correct it or is there a better way to do this?
Range(lastRow + 3, "L:R").Select
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
End With
Thank you.
I have a dynamic range with column headings (from columns A to R) for which I need to add totals to each columns from L to R. I have the following code which works;
Dim lastRow As Long
lastRow = Cells(Rows.Count, "D").End(xlUp).Row
Cells(lastRow + 3, "L").Formula = "=SUM(L2:L" & lastRow & ")"
Cells(lastRow + 3, "M").Formula = "=SUM(M2:M" & lastRow & ")"
Cells(lastRow + 3, "N").Formula = "=SUM(N2:N" & lastRow & ")"
Cells(lastRow + 3, "O").Formula = "=SUM(O2:O" & lastRow & ")"
Cells(lastRow + 3, "P").Formula = "=SUM(P2:O" & lastRow & ")"
Cells(lastRow + 3, "Q").Formula = "=SUM(Q2:Q" & lastRow & ")"
Cells(lastRow + 3, "R").Formula = "=SUM(R2:R" & lastRow & ")"
I am now trying to get a code that for each of these total numbers in the code above, I want to add a cell border (single line to the top and double line to the bottom). The following code fails in the very first line, can anyone tell me how to correct it or is there a better way to do this?
Range(lastRow + 3, "L:R").Select
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
End With
Thank you.