基于单元格的VBA颜色整行 [英] VBA Color Entire Row Based on Cell Value
本文介绍了基于单元格的VBA颜色整行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果该行中的两个单元格具有相同的值,我正在尝试着色整个行。以下是我现在的代码:
For i = 2 To LastRow
如果工作表(请求结果) .Cells(i,4).Value<工作表(请求结果)。Cells(i,6).Value Then
Cells(i,1).EnitreRow.Interior.ColorIndex = 255
ElseIf Worksheets(Request Results)。Cells我,4).Value =工作表(请求结果)。单元格(i,6).Value然后
单元格(i,1).EntireRow.Interior.ColorIndex = 5296274
如果
Next i
循环首先进入else语句,我得到一个下标超出范围 Cells(i,1).EntireRow.Interior.ColorIndex = 5296274
行错误,我不太确定为什么。有谁知道可能导致这个错误?我尝试的一切都失败了。
解决方案
将ColorIndex更改为Color。
单元格(i,1).EntireRow.Interior.Color = 5296274
/ pre>
I'm trying to color an entire row if two cells in that row have the same value. Here's the code I have right now:
For i = 2 To LastRow If Worksheets("Request Results").Cells(i, 4).Value <> Worksheets("Request Results").Cells(i, 6).Value Then Cells(i, 1).EnitreRow.Interior.ColorIndex = 255 ElseIf Worksheets("Request Results").Cells(i, 4).Value = Worksheets("Request Results").Cells(i, 6).Value Then Cells(i, 1).EntireRow.Interior.ColorIndex = 5296274 End If Next i
The loop goes into the else statement first and I get a "Subscript out of range" error on the
Cells(i, 1).EntireRow.Interior.ColorIndex = 5296274
line and I'm not quite sure why. Does anyone know what could be causing this error? Everything I've tried has failed.解决方案change ColorIndex to Color.
Cells(i, 1).EntireRow.Interior.Color = 5296274
这篇关于基于单元格的VBA颜色整行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文