My current sheet is having data in which few cells having Green color, i need to move or copy those rows in which cell having green colour (only few cells coloured with green)to another sheet. i have written code for that but the loop runs on first column for each row wise but wont checks for every cell in that row. i need to check for every row each cell if any cell in green colour then it should copy and paste the entire row in another sheet on next row
Sub Copy()
lastRow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
sheet2Counter = 1
For i = 1 To lastRow
ConditionalColor = Worksheets("Sheet1").Cells(i, 1).Interior.ColorIndex
Worksheets("Sheet1").Activate
Worksheets("Sheet1").Range("A" & i & " ").Select
If ConditionalColor = 35 Then
ActiveCell.EntireRow.copy
Worksheets("Sheet2").Activate
lastrow1 = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
If Not Worksheets("Sheet2").Range("A" & lastrow1 & " ") = "" And Not i = 1 Then
lastrow1 = lastrow1 + 1
Worksheets("Sheet2").Range("A" & lastrow1 & " ").Select
With Selection
.PasteSpecial Paste:=xlPasteAll
End With
Else
Worksheets("Sheet2").Range("A1").Select
With Selection
.PasteSpecial Paste:=xlPasteAll
End With
End If
Worksheets("Sheet1").Cells(i, 1).Value
End If
Next
End Sub
.Cells(i, 1).Interior.ColorIndex
will not detect conditional formatting. You can use theDisplayFormat
, i.e..Cells(i, 1).DisplayFormat.Interior.ColorIndex
for that. – BigBenConditionalColor
. – BigBen