Hello Spike,
2 Options. You can select the ranges by using Union and then use the
Selection to set the borders like the following.
Note that a space and underscore at the end of a line is a line break in an
otherwise single line of code.
Option 1.
Sub Macro1()
Dim intRows As Long
intRows = 10 'Assigned for testing
Sheets("Sheet1").Select
Union(Range(Cells(5, 4), _
Cells(intRows, 5)), _
Range(Cells(5, 6), _
Cells(intRows, 7))).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub
'End of first Option
'**************************************
2nd Option. No need to select the ranges. Just assign a Union of the ranges
to a variable and use the range variable. (More professional.)
Sub Macro2()
Dim rngBorders As Range
Dim intRows As Long
intRows = 10 'Assigned for testing
With Sheets("Sheet1")
Set rngBorders _
= Union(.Range(.Cells(5, 4), _
.Cells(intRows, 5)), _
.Range(.Cells(5, 6), _
.Cells(intRows, 7)))
End With
rngBorders.Borders(xlDiagonalDown).LineStyle = xlNone
rngBorders.Borders(xlDiagonalUp).LineStyle = xlNone
With rngBorders.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With rngBorders.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With rngBorders.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With rngBorders.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
rngBorders.Borders(xlInsideVertical).LineStyle = xlNone
rngBorders.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub