How to delete selected duplicated entries based on colour and or value

TedX

Board Regular
Joined
Apr 18, 2021
Messages
122
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a long list of names that gets added to every day and I've formatted it so that every time a duplicate appears, the cell background colour goes
zzzzz480.jpg

light green, sometimes they are 2 or 3 cells clumped together, and other times just one by itself. I delete the row, by selecting it and right mouse clicking to show a menu and then selecting delete. This works fine except for the following: The original entry higher in the long list, has a set of numeric values, I want to keep, whilst the lower down the list (new entry) duplicate has no value, that the one I want to delete. So I can't just use a filter to select one colour and delete because I have no control over which duplicate will be deleted, probably the highest duplicate on the list which is the exact opposite of what I want to do.

So I have no problem with selecting the duplicates down the bottom of the list and highlighting them (selecting them), except, I can only delete non-stop runs of rows to delete. In the image, I can only delete 9022 by itself, I can delete 9025 to 9027 inclusive in a single action, but I cannot select 9022 and 9025, 9026 and 9027 all at the one time and delete them. At least I can't do it via Excel directly with a mouse, I assume there is a VBA solution but I can't seem to work it out. All help would be appreciated, I suspect this is a few simple lines of VBA code using the colour 198 239 206. Thank you.
zzzzz480.jpg
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
RGB is 198 239 206
Hex is #C6EFCE
I couldn't figure out how to actually do the function, I tried all day, about 10 hours worth, but no luck. So I did it in reverse after watching how to change the font colour based on the color index. So I think the number is 35.
 
Upvote 0
198 239 206
Power Query:
Sub DelBlanks
Dim i as long, lr as long
lr = Range("A" & rows.count).end(xlup).row
For i = lr to 1 step -1
If Range("E" & i).Interior.ColorIndex = RGB(198 239 206) Then
Range("E" & i).EntireRow.Delete
End if
Next i
Msgbox ("Action Completed")
End Sub
 
Upvote 0
Using Color Index 35

VBA Code:
Sub DelBlanks
Dim i as long, lr as long
lr = Range("A" & rows.count).end(xlup).row
For i = lr to 1 step -1
If Range("E" & i).Interior.ColorIndex = 35 Then
Range("E" & i).EntireRow.Delete
End if
Next i
Msgbox ("Action Completed")
End Sub
 
Upvote 0
198 239 206
Power Query:
Sub DelBlanks
Dim i as long, lr as long
lr = Range("A" & rows.count).end(xlup).row
For i = lr to 1 step -1
If Range("E" & i).Interior.ColorIndex = RGB(198 239 206) Then
Range("E" & i).EntireRow.Delete
End if
Next i
Msgbox ("Action Completed")
End Sub
zzzzz481.jpg


I got this Compile Error, even before I ran it, the line was in red. The line that started with: If Range("E"
 
Upvote 0
I ran the script with the colour index of 35, it ran through till the MsgBox came up and said it was completed, but nothing actually happened that I could see. Perhaps 35 isn't the magic number, but when I do have the light green background in the cell, and I have text in it that's 35, the text disappears into the background. A crude test I know but, that's all I've got.
 
Upvote 0
Try this instead.

VBA Code:
Sub DelBlanks()
Dim i As Long, lr As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 1 Step -1
If Range("E" & i).Interior.Color = RGB(198, 239, 206) Then
Range("E" & i).EntireRow.Delete
End If
Next i
MsgBox ("Action Completed")
End Sub
 
Upvote 0
Try this instead.

VBA Code:
Sub DelBlanks()
Dim i As Long, lr As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 1 Step -1
If Range("E" & i).Interior.Color = RGB(198, 239, 206) Then
Range("E" & i).EntireRow.Delete
End If
Next i
MsgBox ("Action Completed")
End Sub

No change, unfortunately, it ran through till the MsgBox but there were no deletions, every row was still intact and the duplicate colours remained on the rows where duplicates actually existed. If you are getting sick of me, please say so, I really have been more trouble than I'm probably worth.
 
Upvote 0
Not sick. Because I cannot test your color scheme, I suggest you upload a sample spreadsheet to a third party location such as Box.Net or Dropbox.Com so that I can test my code on your actual data. Only 8-12 records in the worksheet.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top