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
Do you mean as you can achieve with Union?
Option Explicit
Public Sub test()
Dim unionRng As Range
With Worksheets("Table1")
Set unionRng = Union(.Range("B1:B29"), .Range("E1:E29"), .Range("H1:H29"))
End With
unionRng.BorderAround _
ColorIndex:=1
End Sub
You could shorten to:
Public Sub test()
With Worksheets("Table1")
Union(.Range("B1:B29"), .Range("E1:E29"), .Range("H1:H29")).BorderAround _
ColorIndex:=1
End With
End Sub
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