识别红色的单元格 [英] Identify cells in red

查看:116
本文介绍了识别红色的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题通常很简单,但是即使在网上几个论坛上进行研究之后,我仍然没有找到解决方法.

The title may be typically simple, but I did not get a solution yet even after researching over several forums on the net.

让我解释一下这个问题.

Let me explain the problem.

我有一本excel工作簿,如果条件引用其他单元格,则很少使用列.根据单元格的内容,定义单元格的背景色.例如.如果一个单元格为空白,它将自动变为红色.这些红色单元格指示缺少信息.因此,我正在尝试设计一个宏来识别这些红细胞并获取每个红细胞的地址.

I have an excel workbook where few columns uses if conditions that refers other cells. Based on the cell's content, the back color of the cell is defined. For eg. If a cell is blank, it automatically changes to red. These red cells indicates missing information. So I am trying to design a macro to identify these red cells and get the address of each red cell.

为此,我使用了代码进行测试,MsgBox IIf(ActiveCell.Interior.ColorIndex = 3, "Yes", "No")

For this I used the code for testing, MsgBox IIf(ActiveCell.Interior.ColorIndex = 3, "Yes", "No")

但这不起作用.原因是,宏将颜色索引标识为--4142,而不管它是什么颜色.无论是白色,蓝色还是红色,它仍然显示-4142.

But this does not work. The reason is, the macro identifies the color index as -4142 irrespective of what color it is. Whether it is white or blue or red, it still shows -4142.

当我在论坛上问这个问题时,我被重定向到此页面.

When I asked this question in a forum, I was redirected to this page.

http://www.cpearson.com/excel/CFColors.htm

我测试了该页中给出的功能.对于我创建的示例工作簿来说,它工作正常.但是不在我要验证的工作簿中.

I tested the functions given in that page. It works fine for the sample workbooks I created. But not in the workbook that I am trying to validate.

能请你帮我吗?

推荐答案

使用以下对我有用的方法,在该方法中,我将C的一些单元格设置为默认红色.

Using the following works for me where I made a few cells in C default red.

Dim ws As Worksheet
Set ws = Sheets("sheet1")
Dim i As Integer
i = 1
Do Until i = 11
    If ws.Range("C" & i).Interior.Color = RGB(255, 0, 0) Then
        debug.print "C" & i & "  is red!!"
    End If
i = i + 1
Loop

这也可以在colorindex = 3下使用,我认为您的问题是activecellIIf

This also works using colorindex = 3 I think your problem is a combination of activecell and IIf

这篇关于识别红色的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆