Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-28-2014, 11:30 AM
mbesspiata mbesspiata is offline Shorter VBA for creating borders for cells Windows 7 64bit Shorter VBA for creating borders for cells Office 2010 64bit
Advanced Beginner
Shorter VBA for creating borders for cells
 
Join Date: Mar 2011
Location: Virginia
Posts: 57
mbesspiata is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 07-28-2014, 12:35 PM
whatsup whatsup is offline Shorter VBA for creating borders for cells Windows 7 64bit Shorter VBA for creating borders for cells Office 2010 32bit
Competent Performer
 
Join Date: May 2014
Posts: 137
whatsup will become famous soon enough
Default

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
Reply With Quote
  #3  
Old 07-28-2014, 12:37 PM
mbesspiata mbesspiata is offline Shorter VBA for creating borders for cells Windows 7 64bit Shorter VBA for creating borders for cells Office 2010 64bit
Advanced Beginner
Shorter VBA for creating borders for cells
 
Join Date: Mar 2011
Location: Virginia
Posts: 57
mbesspiata is on a distinguished road
Default

Good to know. Thank you for the response. I knew that seemed like a lot for just a fairly simple task.

Thanks again.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shorter VBA for creating borders for cells Creating borders in word joechidwala Word 2 02-05-2014 05:33 AM
Shorter VBA for creating borders for cells How to create shorter docs from large base template? Preloader Word 13 10-19-2013 09:39 PM
Shorter VBA for creating borders for cells 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
Shorter VBA for creating borders for cells PDF conversion creating borders around text BrazzellMarketing Word 4 01-17-2011 01:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:03 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft