表格边框未填写

时间:2015-10-07 16:07:23

标签: excel vba excel-vba

我正在尝试使用以下内容自动填充单元格的顶部和底部表格边框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

我尝试了其他在线代码来解决同一目标。我在网上找到的代码都没有 - 但似乎对其他人都有效!

1 个答案:

答案 0 :(得分:1)

我认为你需要遍历每个单元格,例如:

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