我的问题:
我想遍历一个范围,每当它找到条件格式化的单元格时,它应该将单元格复制到左边的单元格。然后将其粘贴到另一个工作表中。
我的代码很容易遍历单元格,但不会复制信息,并将其粘贴到另一张表格中。
我的代码:
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
我应该在我的“If c Is”行中写什么来让宏做我想做的事情?
答案 0 :(得分:0)
我不确定我是否理解需要做一系列范围,但为什么不直接使用
If c.FormatConditions.Count = 1 Then