查找具有特定内部颜色的单元格 [英] Finding cells with certain interior color

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

问题描述

我正在使用此代码查找特定颜色(通过条件格式更改)的单元格,然后根据该行中的值将其交换到另一张纸上.但是,该宏运行并且什么也没找到.没有错误消息,只是没有找到任何单元格(在此测试中,我已将其切换为RGB 255、0、0).我在这里做什么错了?

I'm using this code to locate cells that are a certain color (changed by conditional formatting), then based on that values from the row are swapped to another sheet. However, the macro runs and just doesn't find anything. No error message, it's just not locating any cells (that I've switched to RGB 255, 0, 0 for this test). What am I doing wrong here?

Sub ChangeAccountDetailsForMay()

Dim ws As Worksheet
Set ws = Sheets("comparison")
Dim destws As Worksheet
Set destws = Sheets("Account Detail")
Dim i As Integer
Dim j As Integer

For i = 24 To 3205
    If ActiveWorkbook.Sheets("comparison").Range("BF" & i).Interior.Color = RGB(255, 0, 0) Then 'Might be RGB 218 148 148
        MsgBox "Found one at row " & i & "!"
        For j = 25 To 3077
            If ActiveWorkbook.Sheets(destws).Range("J" & j).Value = ActiveWorkbook.Sheets(ws).Range("J" & i).Value And ActiveWorkbook.Sheets(destws).Range("L" & j).Value = ActiveWorkbook.Sheets(ws).Range("L" & i).Value Then
                ActiveWorkbook.Sheets(destws).Range("BD" & j).Value = ActiveWorkbook.Sheets(ws).Range("BB" & i).Value
                ActiveWorkbook.Sheets(destws).Range("BE" & j).Value = ActiveWorkbook.Sheets(ws).Range("BC" & i).Value
                ActiveWorkbook.Sheets(destws).Range("BF" & j).Value = ActiveWorkbook.Sheets(ws).Range("BD" & i).Value
            End If
        Next j
    End If
Next i

MsgBox "Done!", vbInformation, "Success!"
End Sub

推荐答案

要获得条件格式设置提供的单元格颜色,必须使用DisplayFormat

To get the color of the cell that is provided from Conditional Formatting one must use DisplayFormat

...Range ("BF" & i).DisplayFormat.Interior.Color...

这篇关于查找具有特定内部颜色的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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