I have about 500k row data. I have highlighted duplicated cells in A column using conditional formatting.
I want to write VBA code to check for highlighted cells in red color in column A and then cut and paste respective entire row to a new sheet.
Have in mind that when you remove one cell which it is colored due to duplication, the other cell which was also colored become non color if there are not other cells with the same value. Modify if needed and try:
Option Explicit
Sub Insert()
Dim LastRowS1 As Long, LastRowS2 As Long, i As Long
LastRowS1 = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row
For i = LastRowS1 To 2 Step -1
If Sheet1.Range("A" & i).DisplayFormat.Interior.ColorIndex = 38 Then
LastRowS2 = Sheet2.Cells(Sheet2.Rows.Count, "A").End(xlUp).Row
Sheet1.Range("A" & i).Cut Sheet2.Range("A" & LastRowS2 + 1)
Sheet1.Rows(i).EntireRow.Delete
End If
Next i
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.