My issue:
I want to loop through a range, and whenever it finds a coloured cell, it should copy the cell to the left to the cell to the right of it. And then afterwards paste it into an other worksheet.
My sheet called “Compare” compares two sets of data, whereas a FormatConditions is applied as xlUniqueValues... The two sets of data, should contain the same data, but sometimes, there will be some, which are not within the other range. It is these cells that I am interested in finding with my loop, and then doping the processes if the criteria is met.
My code doesn't loop through the cells and returns me this message:
Run-time error '438': Object doesn't support this property or method
A screenshot of some of the data in Sheet "Compare":
My Code:
Sub LoopForCondFormatCells()
Dim sht3, sht4 As Worksheet
Dim ColB, c As Range
Set sht3 = Sheets("Compare")
Set sht4 = Sheets("Print ready")
ColB1 = sht3.Range("G3:G86")
Set ColB = Range(ColB1)
For Each c In ColB.Cells
If c.FormatConditions.Type = xlUniqueValues Then 'Error here!
CValue = c.Address(False, False, xlA1)
CValueOffsetL = sht3.Range(CValue).Offset(0, -1).Address(False, False, xlA1)
CValueOffsetR = sht3.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.Range(KvikOffIns).PasteSpecial xlPasteAll
End If
Next c
Goal:
I want the macro to loop through the cells, and find whatever cells, which has the FormatConditions type "xlUniqueValues". Whenever it comes across a cell, which is FormatConditions type "xlUniqueValues", it should do the steps:
CValue = c.Address(False, False, xlA1)
CValueOffsetL = sht3.Range(CValue).Offset(0, -1).Address(False, False, xlA1)
CValueOffsetR = sht3.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.Range(KvikOffIns).PasteSpecial xlPasteAll
What should I write in my "If c Is" line to get the macro to do what I want it to do?
ColB1 = sht3.Range("G3:G86")
returns an Array (default Values property of range). thenSet ColB = Range(ColB1)
whereColB1
is an array, throughs an error:1004
– chris neilsen