border 」标签的归档

Set Border

通过Union将个Range连接在一起,一次过添加border, 减少与Worsheet之间的交换.
Function SetBoarder(rng)

    rng.Borders(xlEdgeLeft).Weight = xlMedium
    rng.Borders(xlEdgeTop).Weight = xlMedium
    rng.Borders(xlEdgeBottom).Weight = xlMedium
    rng.Borders(xlEdgeRight).Weight = xlMedium

End Function

Sub FormatBoarder()
Dim rng As Range
Dim iRow As Integer
Dim iCol As Integer
Dim iStartRow As Integer, iEndRow As Integer, iStartCol As Integer, iEndCol As Integer

iStartRow = 3
iEndRow = 20
iStartCol = 4
iEndCol = 10

For iRow = iStartRow To iEndRow
    If Rows(iRow).RowHeight = 37 Then
        For iCol = iStartCol To iEndCol Step 2
            If Columns(iCol).ColumnWidth = 8.38 Then
                Set rng = Union(Cells(iRow - 1, iCol), Cells(iRow, iCol), Cells(iRow + 1, iCol), _
                            Cells(iRow - 1, iCol).Offset(0, 1), Cells(iRow, iCol).Offset(0, 1), Cells(iRow + 1, iCol).Offset(0, 1), _
                            Cells(iRow - 1, iCol).Offset(0, -1), Cells(iRow, iCol).Offset(0, -1), Cells(iRow + 1, iCol).Offset(0, -1))
                Call SetBoarder(rng)
            End If
        Next
    End If

Next iRow
End Sub
article clipper remember Set Border