[英]Finding cells with certain interior color
我正在使用此代碼來定位特定顏色的單元格(通過條件格式更改),然后基於該行中的值將其交換到另一張工作表中。 但是,該宏運行並且什么也沒找到。 沒有錯誤消息,只是沒有找到任何單元格(在此測試中,我已將其切換為RGB 255、0、0)。 我在這里做錯了什么?
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.