Border around each cell in a range

前端 未结 7 1849
你的背包
你的背包 2020-12-14 00:38

I am trying to create a simple function that will add borders around every cell in a certain range. Using the wonderful recording this generates a ton of code which is quite

7条回答
  •  醉梦人生
    2020-12-14 01:01

    I have a set of 15 subroutines I add to every Coded Excel Workbook I create and this is one of them. The following routine clears the area and creates a border.

    Sample Call:

    Call BoxIt(Range("A1:z25"))
    

    Subroutine:

    Sub BoxIt(aRng As Range)
    On Error Resume Next
    
        With aRng
    
            'Clear existing
            .Borders.LineStyle = xlNone
    
            'Apply new borders
            .BorderAround xlContinuous, xlThick, 0
            With .Borders(xlInsideVertical)
                .LineStyle = xlContinuous
                .ColorIndex = 0
                .Weight = xlMedium
            End With
            With .Borders(xlInsideHorizontal)
                .LineStyle = xlContinuous
                .ColorIndex = 0
                .Weight = xlMedium
            End With
        End With
    
    End Sub
    

提交回复
热议问题