Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coding For Borders on Ranges

Status
Not open for further replies.

robcarr

Programmer
May 15, 2002
633
GB
Dear All,

IS there easier coding to add a bold border around a range and then make each box line in the range be highlighted with a thin line. every time i record the procedure I get loads and loads of coding, is there a way to speed this up or make the coding less as, I am trying to speed up the macros. I have used the displayalerts and calculations commands to speed up coding, but I thought I could speed up the borders as this seems to take some time. Here is an example of the coding I get, I need to get the same affect as the coding, but in half the time if possible.

Range("B2:L25").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Range("A1").Select
End Sub
 
I'm trying to get the hang of coding, but I think adding this second line to Bryan's code should do the outside border the way you like:

Range("B2:L25").BorderAround , xlMedium

 
Almost Shaun.

I'd forgotten about the thick border. Thgat means two lines of code:

Code:
Range("B2:L25").Borders.LineStyle = xlContinuous
Range("B2:L25").BorderAround Weight:=xlMedium
 
Almost Shaun.

I'd forgotten about the thick border. That means two lines of code:

Code:
Range("B2:L25").Borders.LineStyle = xlContinuous
Range("B2:L25").BorderAround Weight:=xlMedium
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top