VBA内部颜色搜索和单元格管理

时间:2017-07-16 23:14:55

标签: vba colors

我一直在学习VBA并且对一些概念有一定的把握,但是我还在学习,所以保持简单。

我无法让代码识别内部单元格颜色并按照我的意愿管理彩色单元格。

以下是我的代码。

'highlight duplicate data'
Windows("name of workbook").Activate

Sheets("name of sheet").Activate
Columns("C:C").Select
   Selection.FormatConditions.AddUniqueValues
   Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
   Selection.FormatConditions(1).DupeUnique = xlDuplicate

     With Selection.FormatConditions(1).Font
        .Color = 1
        Selection.FormatConditions(1).Interior.ColorIndex = 3
     End With

'到目前为止一切正常,细胞变红了

'consolidate red cells codes'
Dim sampi As Integer

  With ActiveSheet
    refcells = .Cells(.Rows.Count, 3).End(xlUp).Row
  End With

For sampi = 6 'my data starts from here'  To refcells

Cells(sampi, 3).Activate

If Cells(sampi, 3).Interior.ColorIndex = 3 Then redcells = Cells(sampi, 3) Else GoTo nextsampi 'This always comes out as false'

Cells.Find(What:=redcells, After:=ActiveCell, LookIn:=xlFormulas, lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Select

Selection.Copy

Range("a1001").PasteSpecial



nextsampi:

    Next sampi


Call nextsub(1) 

我的所有范围都被定义为它们应该是,并且活动单元格按照我的预期移动,但是“if”语句永远不会为真,尽管在C列中可以看到红色单元格。我已启用屏幕更新以及我能想到的所有其他内容的。

任何建议都表示赞赏。

尔杰斯

0 个答案:

没有答案