Cell border on Totals number at bottom of range

deduwa

Board Regular
Joined
Jul 28, 2015
Messages
110
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.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try this.
Code:
    With Range("L" & lastRow + 3).Resize(, 7)
    
        With .Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
    
        End With
    
        With .Borders(xlEdgeBottom)
            .LineStyle = xlDouble
            .Weight = xlThick
    
        End With
        
    End With
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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