I've been learning VBA and have a moderate grasp of some concepts, however I'm still learning so keep it simple.
I am having trouble getting my code to recognise the interior cell colour and to manage the coloured cells how I desire.
Below is my code.
'highlight duplicate data'
Windows("name of workbook").Activate
Sheets("name of sheet").Activate
Columns("C:C").Select
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = 1
Selection.FormatConditions(1).Interior.ColorIndex = 3
End With
'So far all is working well and the cells turn red'
'consolidate red cells codes'
Dim sampi As Integer
With ActiveSheet
refcells = .Cells(.Rows.Count, 3).End(xlUp).Row
End With
For sampi = 6 'my data starts from here' To refcells
Cells(sampi, 3).Activate
If Cells(sampi, 3).Interior.ColorIndex = 3 Then redcells = Cells(sampi, 3) Else GoTo nextsampi 'This always comes out as false'
Cells.Find(What:=redcells, After:=ActiveCell, LookIn:=xlFormulas, lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Select
Selection.Copy
Range("a1001").PasteSpecial
nextsampi:
Next sampi
Call nextsub(1)
All my ranges are defined as they should be and the active cell moves as I expected, but the 'if' statement is never true despite red cells being visible in column C. I have enabled screen updating and everything else I can think of.
any suggestions are appreciated.
Jess