我写的,好像比楼主的更麻烦一点,呵呵 Sub hjs()
Dim irow%, icol%, j% Application.ScreenUpdating = False
With Range("a2").CurrentRegion
irow = .Rows.Count '当前区域行的总数
icol = .Columns.Count '当前区域列的总数
.Borders.LineStyle = xlNone '清除当前区域所有的边框
End With Add_border Cells(1, 1).Resize(2, 1) '增加a1:b1的边框
Add_border Cells(3, 1).Resize(irow - 2, 1) '增加a3和下面单元格的边框
For j = 2 To icol Step 3 '每3列循环一次,增加边框
Add_border Cells(1, j).Resize(2, 3)
Add_border Cells(3, j).Resize(irow - 2, 3)
Next
End Sub Sub Add_border(rng As Range) '加边框,上下左右四边
With rng
.Borders(xlEdgeLeft).LineStyle = xlContinuous '左
.Borders(xlEdgeTop).LineStyle = xlContinuous '上
.Borders(xlEdgeBottom).LineStyle = xlContinuous '下
.Borders(xlEdgeRight).LineStyle = xlContinuous '右
End With
End Sub |