检查单元格是否是某种颜色,如果是这样的复制数据

我需要能够做到以下几点。

对于给定的数据列(列长度可能根据天的工作量而变化)

检查第一个单元格是否为绿色(在excel .colour = 5296274中)

如果是,则复制数据并将(特殊)数据粘贴到同一行的不同列中

对第一列中的每个单元格重复整个练习,直到第一列中有数据的所有单元格都被检查,然后过程完成。

试试这些线路上的东西。 此代码没有被放在任何表或testing。 另外,它包含你将不得不取代的伪代码

Dim myspecifiedcolor= ' put your color here Dim countOfCells = worksheetfunction.counta("A:A") Dim cellsProcessed as integer cellsProcessed = 0 <loop over all cells in column A> if <cell.backgroundcolor = myspecifiedcolor> then range("P"+cstr(<current cell>.row)).value = <current cell>.value cellsProcessed = cellsProcessed +1 end if if cellsProcessed = countOfCells then <exit loop> end if 'move to next cell <end loop> 

这将是你如何循环单元格的select。 您可以使用或定期while / for循环。

6年后,这是这个问题的答案:

  Option Explicit Dim i As Integer Dim wsh As Worksheet Dim mycolor As Long Sub Color_identifier() Set wsh = ActiveSheet mycolor = 5296274 i = 1 While wsh.Cells(i, 1) <> "" If wsh.Cells(i, 1).Interior.Color = mycolor Then wsh.Cells(i, 2) = wsh.Cells(i, 1).Value i = i + 1 Wend ' End Sub