Search code examples
excelvbarangeborderline

VBA lines for multiple ranges


I want multiple borders for the rows B1, E1 and H1. How can I extend the range command without repeating it over and over again?

the code is:

 Worksheets("Table1").Range("B1:B29").BorderAround _
 ColorIndex:=1

Solution

  • Alternate using Intersect:

    Sub tgr()
    
        With Worksheets("Table1")
            Intersect(.Range("1:29"), .Range("B:B,E:E,H:H")).BorderAround , , 1
        End With
    
    End Sub