本文介绍了范围内的备用行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想出了以下方法来替换指定范围内的行颜色:
I've come up with the following to alternate row colors within a specified range:
Sub AlternateRowColors()
Dim lastRow as Long
lastRow = Range("A1").End(xlDown).Row
For Each Cell In Range("A1:A" & lastRow) ''change range accordingly
If Cell.Row Mod 2 = 1 Then ''highlights row 2,4,6 etc|= 0 highlights 1,3,5
Cell.Interior.ColorIndex = 15 ''color to preference
Else
Cell.Interior.ColorIndex = xlNone ''color to preference or remove
End If
Next Cell
End Sub
可以,但是有没有更简单的方法?
That works, but is there a simpler method?
如果您的数据不包含预先存在的颜色,则可能会删除以下代码行:
The following lines of code may be removed if your data contains no pre-exisiting colors:
Else
Cell.Interior.ColorIndex = xlNone
推荐答案
可以使用条件格式来替换行颜色:
Alternating row colors can be done using conditional formatting:
这篇关于范围内的备用行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!