TkdKidSnake
Active Member
- Joined
- Nov 27, 2012
- Messages
- 255
- Office Version
- 365
- Platform
- Windows
Hi all,
I am really struggling to use VBA to automatically add borders - see below:
Data is always from column A to S but varies in length
Task 1 - Add an extra think border around the whole worksheet (Code is below)
So essentially I just need a way of selecting all the cells from A1 to the last populate cell in column A and then across to column S
Task 2, In the same selected area as above I also want to add a dividing line when the data value changes from B2 through to the end of the document
So fundamentally if the were 3 rows with 841 in and then it changed to 842 I want a think line to be placed in between to separate them.
So assuming the code below would be part of it
If anyone can help it would be greatly appreciated.
I am really struggling to use VBA to automatically add borders - see below:
Data is always from column A to S but varies in length
Task 1 - Add an extra think border around the whole worksheet (Code is below)
So essentially I just need a way of selecting all the cells from A1 to the last populate cell in column A and then across to column S
Code:
Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Task 2, In the same selected area as above I also want to add a dividing line when the data value changes from B2 through to the end of the document
So fundamentally if the were 3 rows with 841 in and then it changed to 842 I want a think line to be placed in between to separate them.
So assuming the code below would be part of it
Code:
With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
If anyone can help it would be greatly appreciated.