#1
|
|||
|
|||
Shorter VBA for creating borders for cells
I am always placing borders around cells in my finished reports and the vba for that is so large. Is there a shorter vba code for doing that. Below is one for just 10 cells.
Range("AG2:AH6").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With There must be a shorter/quicker way to do this. Mike |
#2
|
|||
|
|||
Hi Mike
If you're fine with the default of borders, you don't have to include all properties. What you've got, is the result of the macro-recorder, which includes the properties to show what's possible. Still, it's not a lot shorter because borders are applied in sections: Code:
Sub Do_Borders() With Range("AG2:AH6") .Borders(xlEdgeLeft).LineStyle = xlContinuous .Borders(xlEdgeTop).LineStyle = xlContinuous .Borders(xlEdgeBottom).LineStyle = xlContinuous .Borders(xlEdgeRight).LineStyle = xlContinuous .Borders(xlInsideVertical).LineStyle = xlContinuous .Borders(xlInsideHorizontal).LineStyle = xlContinuous End With End Sub |
#3
|
|||
|
|||
Good to know. Thank you for the response. I knew that seemed like a lot for just a fairly simple task.
Thanks again. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating borders in word | joechidwala | Word | 2 | 02-05-2014 05:33 AM |
How to create shorter docs from large base template? | Preloader | Word | 13 | 10-19-2013 09:39 PM |
Differences in borders at page break in merged cells | Sudlav | Word Tables | 2 | 05-23-2013 11:50 PM |
borders disappear from merged cells when pasting from excel | joba | Word | 0 | 09-10-2012 11:35 AM |
PDF conversion creating borders around text | BrazzellMarketing | Word | 4 | 01-17-2011 01:09 PM |