Border around each cell in a range

前端 未结 7 1875
你的背包
你的背包 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 00:51

    You only need a single line of code to set the border around every cell in the range:

    Range("A1:F20").Borders.LineStyle = xlContinuous

    It's also easy to apply multiple effects to the border around each cell.

    For example:

    Sub RedOutlineCells()
        Dim rng As Range
    
        Set rng = Range("A1:F20")
    
        With rng.Borders
            .LineStyle = xlContinuous
            .Color = vbRed
            .Weight = xlThin
        End With
    End Sub
    

提交回复
热议问题