0

Does anyone knows idea of my below problem in VBA excel

Macro needs to check 5 cells(Continues) in a 1 row.. Totally more than 500 rows are there ..if anyone cell color in a row has color “red” means it has to mention “new” in some column ..

Any idea or solution.. ??

i use the below code , to check any cell in single(or selected) column has red ...

Does anyone knows idea of my below problem in VBA excel

Macro needs to check 5 cells(Continues) in a 1 row.. Totally more than 500 rows are there ..if anyone cell color in a row has color “red” means it has to mention “new” in some column ..

Any idea or solution.. ??

i use the below code for to check any cell in single has red ...

Sub test()

    Dim erange as range

    for each erange in selection

        if erange.interior.color = red then
            Erange.offset(0,1)="New"
        end if 

    next erange

end if
4

1 回答 1

1

我计划把它作为评论,但是这永远不适合在那里。

有谁知道我在 VBA excel 中的以下问题的想法

您的代码中有两个主要错误。

首先,Red不会评估为 Excel 中的有效颜色。

将该行更改为

 if erange.interior.color = vbRed then

或者

 If erange.Interior.ColorIndex = 3 Then

其次,您缺少一个End Sub. 将最后end if一个替换为End Sub

现在到你的主要问题。上面的代码不会帮助您检查 5 个连续的单元格是否有Red颜色。一种方法是使用此逻辑

循环遍历您的范围并设置erange为由 5 个单元格组成例如,如果您的范围是 A1:C10,那么在您的循环中,您的第一个范围将是 A1:A5,然后是 A2:A6,然后是 A3:A7,依此类推......一旦你有你的范围然后你检查范围中的每个单元格是否都有红色。希望这能给你一个开始。

于 2012-05-14T08:58:18.673 回答