我正在使用以下vba代码来应用条件格式。Vba只应用条件格式的顶部/底部边框?
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
的边框显示为这样:
但我希望它看起来像这样:
我想只设置顶部/底部像这样的边界:
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
但我不断收到一个错误,无法设置边框类的linestyle属性。
请有人能告诉我我要去哪里吗?
尝试录制宏,而使用顶部设置条件格式边界格式。你会看到,'Excel'本身将使用'.Borders(xlTop)'而不是'.Borders(xlEdgeTop)'。所以可能[边框对象](https://msdn.microsoft.com/en-us/library/office/ff837809.aspx)与[FormatCondition.Borders](https:// msdn。 microsoft.com/en-us/library/office/ff196030.aspx)以这种没有记录的方式。 –