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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Welcome TedX
We cannot manipulate data in a picture. Please reload your sample using XL2BB
 
Upvote 0
Welcome TedX
We cannot manipulate data in a picture. Please reload your sample using XL2BB
Thanks, Alansidman, but there is no code per see, it's just a list of names, straight-out text. I just want to delete more than one row at a time without using sort or filter. I want to visually select the rows I want to delete and then delete them in one go. As I explained, Excel doesn't permit this, I can select some rows and delete them, but not select them all if there are gaps in the rows, meaning that I want to keep some rows. This should be really simple. The question is, why can't I select rows of my choice and delete them all at the same time? I will admit that there is code in the columns that have numeric output, if that helps. I did look at adding XL2BB but couldn't find it in my add-ins, sorry. :rolleyes:
 
Upvote 0
Welcome TedX
We cannot manipulate data in a picture. Please reload your sample using XL2BB
I persisted and think I got XL2BB working, I hope I haven't wasted your time Alansidman. :cautious:


XbetForm.xlsm
ABCDEFGHIJKABACADAEAFAGAHAIAJAK
911069.0170.01-1.0070.01INTHELAPOFTHEGODS70.0172.0170.01270.0170.0177.0165.0171.01INTHELAPOFTHEGODS62 
911169.0170.01-1.0070.01SVANEKE70.0172.0170.01270.0170.0177.0165.0171.01SVANEKE62 
911269.0170.01-1.0070.01COGENT70.0172.0170.01270.0170.0177.0165.0171.01COGENT57 
911369.0170.01-1.0070.01LAVA70.0172.0170.01270.0170.0177.0165.0171.01LAVA56 
911469.0170.01-1.0070.01WIESENBACH70.0172.0170.01270.0170.0177.0165.0171.01WIESENBACH 
911569.0170.01-1.0070.01MORNINGTON MASK70.0172.0170.01270.0170.0177.0165.0171.01MORNINGTON MASK58 
911669.0170.01-1.0070.01MY BUTTONS BIGGER70.0172.0170.01270.0170.0177.0165.0171.01MY BUTTONS BIGGER54 
911769.0170.01-1.0070.01SASSOON70.0172.0170.01270.0170.0177.0165.0171.01SASSOON51 
911869.0170.01-1.0070.01RAJPIPLA70.0172.0170.01270.0170.0177.0165.0171.01RAJPIPLA48 
911969.0170.01-1.0070.01VERDI70.0172.0170.01270.0170.0177.0165.0171.01VERDI47 
9120-1.00-1.000.00Fake name 12.0020.007.00-5.001.00Fake name 1 
9121-1.00-1.000.00COGENT2.0020.007.00-5.001.00COGENT 
9122-1.00-1.000.00Fake name 22.0020.007.00-5.001.00Fake name 2 
9123-1.00-1.000.00WIESENBACH2.0020.007.00-5.001.00WIESENBACH 
9124-1.00-1.000.00MORNINGTON MASK2.0020.007.00-5.001.00MORNINGTON MASK 
9125-1.00-1.000.00Fake name 32.0020.007.00-5.001.00Fake name 3 
9126-1.00-1.000.002.0020.007.00-5.001.000.00 
9127-1.00-1.000.002.0020.007.00-5.001.000.00 
Rating
Cell Formulas
RangeFormula
AB9110:AB9127AB9110=$D9110
AC9110:AC9127AC9110=SUM($H9110+5)
AD9110:AD9127AD9110=SUM($D9110-5)
AE9110:AE9127AE9110=SUM($D9110+1)
A9110:A9127A9110=SUM($C9110:$D9110)
D9110:D9127D9110=$B9110
H9110:H9127H9110=SUM($J9110:$K9110)
AG9110:AG9127AG9110=[@[Horse (Xbet)]]
AJ9110:AJ9127AJ9110=IFERROR(VLOOKUP(Table8[@HorseNames],Benchmark!A:B,2,FALSE),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
AJ:AJCell Value=0textNO
E15160:E1048576,E8173:E15157,E7725:E8167,E1:E4505,E4508:E7723Cell ValueduplicatestextNO
 
Upvote 0
I believe I understand what you want. With your cursor on the row number, click on Enter and at the same time hold down the CTL button. Now with the CTL button still depressed, select the next row to delete and continue down. When all have been selected. Click on the Delete button.
 
Upvote 0
I believe I understand what you want. With your cursor on the row number, click on Enter and at the same time hold down the CTL button. Now with the CTL button still depressed, select the next row to delete and continue down. When all have been selected. Click on the Delete button.
Thanks again Alansidman, I tried the multiple select the way you said and indeed I have been doing that for quite some time (so you are on the money), however, it doesn't work on this specific worksheet. I copied and pasted the data into a new worksheet and it works perfectly, the rows delete as hoped. It's as if this worksheet has some error protection built in that I'm not aware of, and it just stops me from deleting non-contiguous rows, once there is a regular row I don't want to delete between them, the delete function greys out. On a replicated new page, the delete stays active and I can select any combination of rows and delete them. There is something different about this specific page. I built that page over the last three years and have not consciously protected it in any way. I do have Vlookups to other worksheets and they are wrapped in Iferror but that is just straight-out Excel that works everywhere else.

Okay, not to let this drop, I have just made a discovery, I have always used my mouse, both left and right buttons extensively, in fact, I hardly ever use a keyboard (my bad), so I just selected the desired rows and actually hit the Delete key on my wireless keyboard and the contents of the rows deleted, this is a major breakthrough for me. :biggrin: I now have to just figure out the best way to close up the blank (now empty rows). Probably a combination of filtering out the blanks I guess, or sorting the entire table so the empty rows should go to the bottom. I'll play around with these ideas but I'd stumped as to why I get a different response using the mouse as opposed to the keyboard, but I am happy and I thank you very much. If you can think of a better way of closing the blank rows 9268, 9270, 9271, 9273, 9275 and 9276 that would be great. Thanks again Alansidman, you are a cool bloke 👍

XbetForm.xlsm
ABCDEFGHIJKABACADAEAFAGAH
926569.0170.01-1.0070.01PROPHET'S CHOICE70.0172.0170.01270.0170.0177.0165.0171.01PROPHET'S CHOICE
926669.0170.01-1.0070.01OUR ELLIE ROSE70.0172.0170.01270.0170.0177.0165.0171.01OUR ELLIE ROSE
926769.0170.01-1.0070.01LADY ANNABEL70.0172.0170.01270.0170.0177.0165.0171.01LADY ANNABEL
9268
9269-1.00-1.000.00Fake 12.0020.007.00-5.001.00Fake 1
9270
9271
9272-1.00-1.000.00Fake 22.0020.007.00-5.001.00Fake 2
9273
9274-1.00-1.000.00Fake 32.0020.007.00-5.001.00Fake 3
9275
9276
Rating
Cell Formulas
RangeFormula
AB9265:AB9267,AB9274,AB9272,AB9269AB9265=$D9265
AC9265:AC9267,AC9274,AC9272,AC9269AC9265=SUM($H9265+5)
AD9265:AD9267,AD9274,AD9272,AD9269AD9265=SUM($D9265-5)
AE9265:AE9267,AE9274,AE9272,AE9269AE9265=SUM($D9265+1)
A9265:A9267,A9274,A9272,A9269A9265=SUM($C9265:$D9265)
D9265:D9267,D9274,D9272,D9269D9265=$B9265
H9265:H9267,H9274,H9272,H9269H9265=SUM($J9265:$K9265)
AG9265:AG9267,AG9274,AG9272,AG9269AG9265=[@[Horse (Xbet)]]
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E15160:E1048576,E7725:E8167,E1:E4505,E4508:E7723,E8173:E15157Cell ValueduplicatestextNO
 
Upvote 0
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 IsEmpty(Range("A" & i).Value) = True Then
Range("A" & i).EntireRow.Delete
End if
Next i
Msgbox ("Action Completed")
End Sub

This is some VBA aircode that you could use to remove the blank rows. This assumes that if Column A is blank, then the entire row will be deleted. Be sure to back up your file before testing.

How to install your new code
  • Copy the Excel VBA code
  • Select the workbook in which you want to store the Excel VBA code
  • Press Alt+F11 to open the Visual Basic Editor
  • Choose Insert > Module
  • Edit > Paste the macro into the module that appeared
  • Close the VBEditor
  • Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)


To run the Excel VBA code:
  • Press Alt-F8 to open the macro list
  • Select a macro in the list
  • Click the Run button
 
Upvote 0
WOW Alansidman, thank you very much. I put the macro into my Personal workbook because I believe I will use this on more than just this current project, it's actually a brilliant bit of kit. I made an example and showed the wife, it was a stellar demonstration. We discussed the time it takes me to click on (select) each row, as my part of the contribution. We figured that if your macro was to select the duplicate (light Green) horse names in column E and then call your DelBlanks macro, that would be the absolute ideal situation.

My scenario in English would be to grab the new rows from the source worksheet and paste them on the last row of the current table (I'm already doing this). Then the current formatting would automatically show the duplicates in light green background cell colour. Then a new macro to select the rows that are duplicated. Then either me physically hit the delete key on the keyboard or for that to be done via VBA. Then a call to your macro to delete the deleted rows.

Is there any way that via VBA you can select each row based on the cell background colour in column E?
 
Upvote 0
Simple answer is Yes. Would need to know that the color index number is.

Click on one of the green cells and run this macro. Then advise what the color index number is.

VBA Code:
Function GetColor(r As Range) As Integer
GetColor = r.Interior.ColorIndex
End Function

Put your cursor on one of the cells colored not by conditional formatting.
Click on the Function Icon (fx)
and click enter.
 
Upvote 0
RGB is 198 239 206
Hex is #C6EFCE
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,904
Members
449,194
Latest member
JayEggleton

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