Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Simplify macro to show grid lines

I recorded a macro to add grid lines to a range of cells, and then I
converted the macro to a more readable format:

Public Sub ShowGridLines(rng As Range)
With rng
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone

With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

With .Borders(xlEdgeTop)...


However, I thought there may be a way to simplify it even more, using
the Borders collection:

Dim b as Border
For Each b in rng.Borders
b.LineStyle = xlContinuous
b.Weight = xlThin
b.ColorIndex = xlAutomatic
Next

This would reduce all that code to six lines.


The problem is this code adds every border, including xlDiagonalDown
and xlDiagonalUp. Does anyone know how to filter these two borders
from the collection? The recorded macro explicity sets these line
styles to "xlNone" (see above).

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Simplify macro to show grid lines

Possibly

Sub efg()
Dim b As Border
i = 0
Set rng = ActiveCell
For Each b In rng.Borders
i = i + 1
If i < 5 And i < 6 Then
b.LineStyle = xlContinuous
b.Weight = xlThin
b.ColorIndex = xlAutomatic
End If
Next
End Sub

--
Regards,
Tom Ogilvy

"Mike K" wrote in message
ups.com...
I recorded a macro to add grid lines to a range of cells, and then I
converted the macro to a more readable format:

Public Sub ShowGridLines(rng As Range)
With rng
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone

With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

With .Borders(xlEdgeTop)...


However, I thought there may be a way to simplify it even more, using
the Borders collection:

Dim b as Border
For Each b in rng.Borders
b.LineStyle = xlContinuous
b.Weight = xlThin
b.ColorIndex = xlAutomatic
Next

This would reduce all that code to six lines.


The problem is this code adds every border, including xlDiagonalDown
and xlDiagonalUp. Does anyone know how to filter these two borders
from the collection? The recorded macro explicity sets these line
styles to "xlNone" (see above).



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel grid lines show when pasting, didn't used to RindaRich Excel Discussion (Misc queries) 1 July 22nd 09 12:38 AM
Cell grid lines won't show up, and have box checked Fran Jones Excel Discussion (Misc queries) 7 January 19th 08 01:14 AM
Show grid lines when printing? TKM New Users to Excel 4 October 21st 06 03:52 AM
Why do some grid lines not show in print preview? Swamp Excel Discussion (Misc queries) 5 September 5th 06 04:34 PM
Show Grid lines Linc Excel Programming 2 November 25th 03 07:41 PM


All times are GMT +1. The time now is 02:28 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"