我能找到堆栈溢出两个代码,但不能把它给一个浅灰色格式化行,其次是白排,帮助将不胜感激,都尝试规范颜色格式每隔一行
Sub Colour(rng As Range, firstColor As Long, secondColor As Long)
rng.Interior.ColorIndex = xlAutomatic
rng.FormatConditions.Add Type:=xlExpression, Formula1:="=MOD(ROW(),2)=0"
rng.FormatConditions(1).Interior.Color = firstColor
rng.FormatConditions.Add Type:=xlExpression, Formula1:="=MOD(ROW(),2)<>0"
rng.FormatConditions(2).Interior.Color = secondColor
End Sub
'Usage:
'
Sub ColourFormatting()
Dim rng As Range
Dim firstColor As Long
Dim secondColor As Long
Set rng = Range("A1:E10")
firstColor = Pattern = xlSolid: PatternColorIndex = xlAutomatic: ThemeColor = xlThemeColorDark1: TintAndShade = -0.149998474074526: PatternTintAndShade = 0
secondColor = TintAndShade = 0: PatternTintAndShade = 0
'
Call Colour(rng, firstColor, secondColor)
End Sub
Sub ShadeEveryOtherRow()
Dim Counter As Integer
'For every row in the current selection...
For Counter = 1 To Range("A1:E30").Rows.Count
'If the row is an odd number (within the selection)...
If Counter Mod 2 = 1 Then
'Set the pattern to xlGray16.
Range("A1:E30").Rows(Counter).Interior.Pattern = xlSolid: PatternColorIndex = xlAutomatic: ThemeColor = xlThemeColorDark1: TintAndShade = -0.149998474074526: PatternTintAndShade = 0
End If
Next
End Sub
真的很困惑。你想添加一个不同的条件格式或只是规则的格式化交替行?如果只是格式化你在“ShadeEveryOtherRow”子版上出现什么错误?这一个似乎应该工作。 – nbayly