我的问题:
我想循环遍历一个范围,每当它找到一个有色单元格时,它应该将单元格复制到左边的单元格到右边的单元格。然后将其粘贴到另一个工作表中。
我的代码很容易在单元格中循环,但不会复制信息,并将其粘贴到另一张表格中。
我的代码:
Sub LoopForCondFormatCells()
Dim sht3, sht4 As Worksheet
Dim ColB, c As Range
Set sht3 = Sheets("Compare")
Set sht4 = Sheets("Print ready")
ColB1 = Range("G3:G86")
Set ColB = Range(ColB1)
For Each c In ColB.Cells
If c.Interior.Color = RGB(250, 191, 143) Then _
'Must be here, where the code is wrong. I actually don't need to look for .Count _
Since I need the code to find a cell, and if it is conditionally formatted _
, then do following steps.
CValue = c.Address(False, False, xlA1)
CValueOffsetL = Range(CValue).Offset(0, -1).Address(False, False, xlA1)
CValueOffsetR = Range(CValue).Offset(0, 1).Address(False, False, xlA1)
sht3.Range(CValueOffsetL, CValueOffsetR).Copy
KvikOffIns = sht4.Range(HosKvikOff).Offset(0, -1).Address(False, False, xlA1)
sht4.Activate
sht4.Range(KvikOffIns).PasteSpecial xlPasteFormats
End If
Next c
End Sub
目标:
我希望宏循环遍历单元格,并找到任何具有颜色" RGB(250,191,143)"的单元格。每当遇到一个用" RGB(250,191,143)"着色的单元格时,它应该执行这些步骤,或者至少是一个有色的单元格:
CValue = c.Address(False, False, xlA1)
CValueOffsetL = Range(CValue).Offset(0, -1).Address(False, False, xlA1)
CValueOffsetR = Range(CValue).Offset(0, 1).Address(False, False, xlA1)
sht3.Range(CValueOffsetL, CValueOffsetR).Copy
KvikOffIns = sht4.Range(HosKvikOff).Offset(0, -1).Address(False, False, xlA1)
sht4.Activate
sht4.Range(KvikOffIns).PasteSpecial xlPasteFormats
我应该在我的"如果c是"是为了让宏做我想做的事情?