Reputation: 17
I am trying to use the following to autofill top and bottom table borders for cells Q2:T200 :
Sub autofiller()
Dim ws As Worksheet
Dim wb As Workbook
Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Pharmacontacts")
With ws.Range("Q2:T200").Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.Color = RGB(91, 155, 213)
End With
With ws.Range("Q2:T200").Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
.Color = RGB(91, 155, 213)
End With
End Sub
The problem is the table borders aren't being filled. I encountered the same problem with:
With Range("Q2:T200").Borders(xlEdgeTop)
.LineStyle = xlContinuous
.color = RGB(91,155,213)
.Weight = xlThin
End With
With Range("Q2:T200").Borders(xlEdgeBottom)
.LineStyle = xlDouble
.color = RGB(91,155,213)
.Weight = xlThick
End With
Also tried this:
With Range("Q2:T200")
With .Rows(.Rows.Count)
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.Color= RGB(91,155,213)
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.Color= RGB(91,155,213)
End With
End With
End With
I've tried other code online that addressed the same objective. None of the code I found online works - but seems to work for everyone else!
Upvotes: 1
Views: 96
Reputation: 6984
I believe you need to loop through each cell, for example:
Sub Button1_Click()
For Each cell In Range("Q2:T200")
With cell.Borders(xlTop)
.LineStyle = xlContinuous
.Color = RGB(91, 155, 213)
.Weight = xlThin
End With
Next cell
For Each cell In Range("Q2:T200")
With cell.Borders(xlBottom)
.LineStyle = xlDouble
.Color = RGB(91, 155, 213)
.Weight = xlThick
End With
Next cell
End Sub
Upvotes: 1