Highlight duplicate cells in non-sequential, non-stationary cells that only contain 7 or 8 digit numbers

larz1620

New Member
Joined
Oct 8, 2013
Messages
1
Hi. I am new to posting so hopefully I do this right. I can't figure out how to attach my file so I pasted part of it below the code. :rolleyes: I changed the actual text (I'm not working on animals) :LOL:

Background:
I have a template my team uses but the conditional formatting does not work well for our diverse requirements. We need to identify duplicate ID numbers within our worksheet (by coloring in the cell). We are constantly updating our worksheet by over writing cell contents, copy/paste/insert/del rows and columns, etc.

Requirements to highlight duplicate cells:
1. don't count as duplicate if cell contains "-" or "na" (which would not be needed if I could get the VBA to recognize only cells with 7 or 8 digit numbers).
2. Only find duplicates if cells contain 7 or 8 digit numbers.

Right now I am using conditional formatting and setting ranges. However, I have to keep resetting the ranges for my team in each of their worksheets every time they add/move/del rows/columns. Other team members just ignore the highlighting which defeats the purpose and causes poor work.

So... to my question. I tried for a few months to figure out a way using VBA to meet the requirements. Currently I have the code below which gives me a run time error #1004 and stops at the command "Set rRange..."

Duplicate cells with 7-8 digit numbers can be contained in various places through out the rows and columns generally grouped like $J$2:$U$5,$J$8:$U$9,$D$10:$G$24 but rows & columns may get added before/after and within these areas. The grouping also crosses over each other causing non-duplicates to highlight when in the cross-section.

I am open to other suggestions too.

This is what I have in VBA...
...
Dim rRange As Range​
Dim rCell As Range​

'I want to identify all DUPLICATE cells in this worksheet ONLY IF the​
' cells contain either 7 or 8 digit numbers...​

Set rRange = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas, xlNumbers)​

rRange.Select.rCell​
Selection.FormatConditions.AddUniqueValues​
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority​
Selection.FormatConditions(1).DupeUnique = xlDuplicate​
With Selection.FormatConditions(1).Font​
.Color = -16383844​
.TintAndShade = 0​
End With​
With Selection.FormatConditions(1).Interior​
.PatternColorIndex = xlAutomatic​
.Color = 13551615​
.TintAndShade = 0​
End With​
Selection.FormatConditions(1).StopIfTrue = False​
'If my request is not possible, how can I name or otherwise identify cells that will not​
' require modifing the macro/conditional formatting if row and or columns are copied​
' and pasted (keep the cell type for copied rows/columns)​

...


clip_image001.png

<tbody>
</tbody>
Color112340015123400161234002012340018
Color212340027123400281234002912340030
Color3----
Color4--12340020-
PropertyAFreeFreeFreeFree
PropertyBFarmFarmFarmFarm
Data ID2340051834005251264742340151
NameLocation1Location2Base IDColor1Color2Color3Color4Base ID12340039123400401234004112340042
FishMI480011234000012340053---note-55--
FishOH4372812340001-12340054--note12---
FishTX7903112340002--12340055-noteg:1, w:26--
BirdMI4805912340003-12340057-12340056note2222
BirdOH4573212340004123400209876432--note--3-
BirdTX8813212340005nananananote-59-
BirdTX881301234000612343436---note1111
CatMI48091123400075330006--12340032note-1--
CatMI48023123400083214000612340057-12340028note--4-
CatOH437281234000923140006--12340053note-1--
CatTX793121234001022340006---note----

<tbody>
</tbody>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi and welcome to the MrExcel Message Board,

I think this works as a conditional format:

=AND(A1>1000000,A1<99999999,COUNTIF($A$1:$N$20,"=" & A1)>1)

I pasted in your data and A1 was the first cell and $A$1:$N$20 was the last cell. That may need to be changed depending on your data range.
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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