PC Review


Reply
Thread Tools Rate Thread

Conditional borders

 
 
Slim Slender
Guest
Posts: n/a
 
      7th Dec 2010
The following procedure places borders conditionally as I want but it
does not stop when the Until condition is met. Instead it continues,
apparently to the bottom of the sheet, then gives an Error 400 which
is no help.
I think the problem is Range("C:C") but I don't know how to fix it.
Also, I would like to precede this in the same procedure with
something that would remove any existing borders. Any help would be
appreciated.

Public Sub DrawBorders()
Dim cell As Range
Dim numRows As Single

numRows = Selection.CurrentRegion.Rows.Count

Do
For Each cell In Range("C:C")
If cell.Offset(1, 0).Value <> cell.Value Then
With Range(Cells(cell.Row, 1), Cells(cell.Row,
5)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = 1
End With
Else
End If
Next cell
Loop Until cell.Row = numRows
End Sub
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      7th Dec 2010
One way that is not too far removed from your way.
There are other ways...
'---
Public Sub DrawBorders_R1()
Dim cell As Range
Dim numRows As Long
Dim rngSelected As Range

Set rngSelected = Application.Intersect(ActiveSheet.Range("C:C"), _
ActiveSheet.UsedRange)
numRows = rngSelected(rngSelected.Rows.Count).Row
Set cell = rngSelected(1, 1)
rngSelected.Resize(, 5).ClearFormats '<<< All formatting removed

Do
If cell.Offset(1, 0).Value <> cell.Value Then
With cell.Resize(1, 5).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = 1
End With
End If
Set cell = cell(2, 1)
Loop Until cell.Row >= numRows
End Sub
'---

Jim Cone
Portland, Oregon USA
http://www.contextures.com/excel-sort-addin.html

..
..
..

"Slim Slender" <(E-Mail Removed)>
wrote in message
news:558e1598-bcac-4b77-920d-(E-Mail Removed)...
The following procedure places borders conditionally as I want but it
does not stop when the Until condition is met. Instead it continues,
apparently to the bottom of the sheet, then gives an Error 400 which
is no help.
I think the problem is Range("C:C") but I don't know how to fix it.
Also, I would like to precede this in the same procedure with
something that would remove any existing borders. Any help would be
appreciated.

Public Sub DrawBorders()
Dim cell As Range
Dim numRows As Single
numRows = Selection.CurrentRegion.Rows.Count
Do
For Each cell In Range("C:C")
If cell.Offset(1, 0).Value <> cell.Value Then
With Range(Cells(cell.Row, 1), Cells(cell.Row, 5)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = 1
End With
Else
End If
Next cell
Loop Until cell.Row = numRows
End Sub
 
Reply With Quote
 
Slim Slender
Guest
Posts: n/a
 
      7th Dec 2010
Jim,
Thanks for your reply. The endless loop problem is solved. However, I
cannot afford to clear all formatting because there is other
formatting in the table besides the thick borders. I have to be able
to remove and replace only the thick borders. Also, this code is
placing the borders across columns A thru G (7 columns, or 5 columns
from C) instead of just A thru C (total of 5 columns). Also, it is
affecting the header row. Can we make it start at row 2 and leave the
header row alone? Thanks again.
 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      7th Dec 2010

Public Sub DrawBorders_R2()
Dim N As Long
Dim numRows As Long
Dim numStart As Long

numStart = 2 'Start row must be 2 or more.
numRows = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row

Application.ScreenUpdating = False
Range(Cells(numStart - 1, 1), Cells(numRows, 5)).Borders.LineStyle = xlLineStyleNone
For N = numStart To numRows
If Cells(N, 3).Offset(1, 0).Value <> Cells(N, 3).Value Then
With Cells(N, 1).Resize(1, 5).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = 1
End With
End If
Next
Application.ScreenUpdating = True
End Sub

--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware

..
..
..

"Slim Slender" <(E-Mail Removed)>
wrote in message
news:84c412a2-a764-4a50-86dd-(E-Mail Removed)...
Jim,
Thanks for your reply. The endless loop problem is solved. However, I
cannot afford to clear all formatting because there is other
formatting in the table besides the thick borders. I have to be able
to remove and replace only the thick borders. Also, this code is
placing the borders across columns A thru G (7 columns, or 5 columns
from C) instead of just A thru C (total of 5 columns). Also, it is
affecting the header row. Can we make it start at row 2 and leave the
header row alone? Thanks again.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
conditional formatting borders PhilosophersSage Microsoft Excel Misc 9 2nd Oct 2009 05:47 PM
Conditional Format Borders clark-ee Microsoft Excel Misc 1 26th Oct 2008 01:21 AM
Borders and conditional formating Patrick C. Simonds Microsoft Excel Worksheet Functions 5 19th Jan 2008 06:03 AM
Re: Conditional Borders? David Biddulph Microsoft Excel Misc 0 9th Jan 2007 03:39 PM
Conditional Formatting and Borders Jrew23 Microsoft Excel Discussion 4 1st Mar 2005 11:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:30 AM.