I am using the following vba code to apply conditional formatting.
Sub ResetConditions()
With Worksheets(1).Range("A9:P1048576")
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=ROW(B9)=ROW(OFFSET($B$9,COUNTA($B:$B)-2,0))"
With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
With .Borders
.LineStyle = xlContinuous
.Weight = xlThin
.Color = vbRed
End With
End With
End With
End Sub
The border is showing as this:
But i want it to look like this:
I am trying to set only top/bottom borders like so:
Sub ResetConditions()
With Worksheets(1).Range("A9:P1048576")
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=ROW(B9)=ROW(OFFSET($B$9,COUNTA($B:$B)-2,0))"
With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.Color = vbRed
End With
End With
End With
End Sub
But i keep getting an error unable to set linestyle property of border class.
Please can someone show me where i am going wrong?
Excel
itself will using.Borders(xlTop)
instead of.Borders(xlEdgeTop)
. So probably Borders Object for ranges differs fromBorders
collection from FormatCondition.Borders in this not documented way. – Axel Richter