我需要能够执行以下操作。检查单元格是否为某种颜色,如果是这样复制数据
对于给定的数据列(列长度可根据天工作量变量)
检查是否所述第一小区是绿色(在Excel .colour = 5296274)
如果是则数据复制和粘贴(特殊)数据转换成不同的列在同一行
重复整个演习在第一列的每个单元格,直到在第一列的所有单元具有数据都经过检查,过程就完成了。
我需要能够执行以下操作。检查单元格是否为某种颜色,如果是这样复制数据
对于给定的数据列(列长度可根据天工作量变量)
检查是否所述第一小区是绿色(在Excel .colour = 5296274)
如果是则数据复制和粘贴(特殊)数据转换成不同的列在同一行
重复整个演习在第一列的每个单元格,直到在第一列的所有单元具有数据都经过检查,过程就完成了。
试试这些行。这段代码没有放在任何表单中或者经过测试。 此外,它还含有伪代码,你将不得不更换
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>
这将是你的选择如何在细胞循环。您可以使用或常规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
什么版本?背景或前景色? – 2010-11-02 10:00:11
看这里http://www.meadinkent.co.uk/excel-color-calcs.htm – 2010-11-02 10:05:02
Excel 2007,背景颜色 – Benji2010 2010-11-02 21:24:27