[英]Finding cells with certain interior color
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).
没有错误消息,只是没有找到任何单元格(在此测试中,我已将其切换为RGB 255、0、0)。 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
...Range ("BF" & i).DisplayFormat.Interior.Color...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.