View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Border formatting row of cells

Hi Howard,

I tested a bit more to make the code easier and more readable. That is
the result:

Sub TestCB()
Dim myRng As Range
Dim rngC As Range
Dim myR As Long
Dim i As Long

With Sheets("BLANK")
myR = WorksheetFunction.Match(.Range("Y1"), _
.Range(.Range("X1") & "DeskRng"), 0)

Set myRng = .Range(.Range("X1")).Rows(myR)
'MsgBox myRng.Address
End With

For i = 1 To myRng.Cells.Count
If myRng.Cells(i).Interior.Pattern = xlNone Then
With myRng.Cells(i)
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = IIf(Not WorksheetFunction.IsOdd(i), _
xlHairline, xlThin)
End With
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlThin
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlThin
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = IIf(WorksheetFunction.IsOdd(i), _
xlHairline, xlThin)
End With
End With
End If
Next i

With Sheets("BLANK")
.Range(.Range("X1")).BorderAround _
ColorIndex:=xlAutomatic, Weight:=xlMedium
End With
End Sub

No more test for column C or Z and no seperate loops for these columns.

Please check the interior color into the ranges. I guess some cells are
white instead of no color.


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2