Following is some VBA code I am wrestling with in trying to create borders that stay within in a dynamic range.
As you can see from the following VBA code and image, I am able to get the code I have written to be dynamic in responding to finding the overall range of the data I want to enclose in borders, except for the thicker vertical borders. These thicker vertical borders are extending below the dynamic range, with row 19, as you can see in the image, constituting the last row in the range in this particular instance.
I would appreciate assistance with making the necessary adjustments in my code to get the thicker vertical borders to work within the dynamic range like the thinner borders do.
Thanks for your assistance!
-John
Sub DynamicRangeBorders()
Dim StartCell As Range
Set StartCell = Range("A11")
Cells.Borders.LineStyle = xlNone
StartCell.CurrentRegion.Borders.LineStyle = xlContinuous
Dim BorderIndex As Variant
For Each BorderIndex In Array(xlEdgeTop, xlEdgeLeft, xlEdgeRight)
With Range("L11:R35").Borders(BorderIndex)
.Weight = xlThick
.ColorIndex = vbBlack
End With
Next BorderIndex
For Each BorderIndex In Array(xlEdgeLeft)
With Range("R11:R35").Borders(BorderIndex)
.Weight = xlThick
.ColorIndex = vbBlack
End With
Next BorderIndex
End Sub
[/IMG]
As you can see from the following VBA code and image, I am able to get the code I have written to be dynamic in responding to finding the overall range of the data I want to enclose in borders, except for the thicker vertical borders. These thicker vertical borders are extending below the dynamic range, with row 19, as you can see in the image, constituting the last row in the range in this particular instance.
I would appreciate assistance with making the necessary adjustments in my code to get the thicker vertical borders to work within the dynamic range like the thinner borders do.
Thanks for your assistance!
-John
Sub DynamicRangeBorders()
Dim StartCell As Range
Set StartCell = Range("A11")
Cells.Borders.LineStyle = xlNone
StartCell.CurrentRegion.Borders.LineStyle = xlContinuous
Dim BorderIndex As Variant
For Each BorderIndex In Array(xlEdgeTop, xlEdgeLeft, xlEdgeRight)
With Range("L11:R35").Borders(BorderIndex)
.Weight = xlThick
.ColorIndex = vbBlack
End With
Next BorderIndex
For Each BorderIndex In Array(xlEdgeLeft)
With Range("R11:R35").Borders(BorderIndex)
.Weight = xlThick
.ColorIndex = vbBlack
End With
Next BorderIndex
End Sub