表格边框没有被填充

我正在尝试使用以下自动填充单元格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 

问题是表格边框没有被填充。 我遇到了同样的问题:

 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 

也试过这个:

 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 

我已经尝试了其他在线代码来解决相同的目标。 没有我在网上find的代码作品 – 但似乎适用于其他人!

我相信你需要遍历每个单元格,例如:

 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