您好,我想通过A列中的值来交替筛选表中的颜色行。
预期的结果将是
-row 2-3 (value=1 A列)将显示一种颜色,例如黄色
-row 4 (column A value=2)将获得另一种颜色
-row 5-6 (A value=3列)将再次变为黄色
如何使用VBA在筛选表中执行此操作?
发布于 2014-08-08 22:22:22
我假设这里着色的条件是值是奇数或偶数。你可以试一试
Sub AlterColour()
Dim intRowCount, intLastRow, intValue, intPreValue as Integer
intLastRow = Application.CountA(Sheets(1).Range("a:a"))
'Set first row to a colour
Sheets(1).Range("a" & 1 ).Interior.ColorIndex = '[An Integer Here, index 36 for yellow]
'Note: inteRowCount = 2 if there is no header, otherwise set to 3
For intRowCount = 2 to intLastRow
intValue = Sheets(1).Range("a" & intRowCount ).Value
intPreValue = Sheets(1).Range("a" & (intRowCount - 1) ).Value
If intValue = intPreValue Then
Sheets(1).Range("a" & intRowCount ).Interior.ColorIndex = '[An Integer Here, index 36 for yellow]
Else
Sheets(1).Range("a" & intRowCount ).Interior.ColorIndex = ' [An Integer Here, index for other colour]
End If
Next
End Subhttps://stackoverflow.com/questions/25205204
复制相似问题