Return Unique Consecutive Duplicate Values across Single Row

  • Thread starter Sam via OfficeKB.com
  • Start date
S

Sam via OfficeKB.com

Hi All,

I have a Named Range called "Data" that spans 8 columns and 7 rows. A Numeric
Value will appear only once in a row. Each row's Numeric Values are in
ascending order. A unique consecutive duplicate MUST be in the SAME column.

I would like to Return across a single row unique consecutive duplicates
(single instance
of a consecutive duplicate value in the SAME column) in ascending order.

Sample Data Layout:

101 102 107 110 145 370 490 501
104 106 107 144 360 430 470 580
125 129 140 150 350 430 460 590
101 102 129 130 149 330 440 578
101 108 120 129 200 280 430 535
100 111 170 175 176 280 420 520
121 189 170 202 229 230 420 521

Expected Results: Unique Duplicate Returned across Single Row
101 107 170 280 420 430

Column 1 = 101
Column 3 = 107, 170
Column 6 = 280, 430
Column 7 = 420


Thanks,
Sam
 
G

Gary''s Student

Sub sam()
Dim s As String
For i = 1 To 8
For j = 2 To 7
v = Cells(j, i).Value
If Cells(j - 1, i).Value = v Then
If s = "" Then
s = v
Else
s = s & "," & v
End If
MsgBox ("column " & i & " " & v)
End If
Next
Next
MsgBox (s)
End Sub

gives result in MSGBOX format. You can modify the code if you need the
results put back into the worksheet.
 
S

Sam via OfficeKB.com

Hi Gary's Student,

Thank you very much for your time and assistance. That's Great! Provides the
desired results.

What do I need to modify to put the results back into the worksheet?

Cheers,
Sam



Gary''s Student wrote:
Sub sam()
Dim s As String
For i = 1 To 8
For j = 2 To 7
v = Cells(j, i).Value
If Cells(j - 1, i).Value = v Then
If s = "" Then
s = v
Else
s = s & "," & v
End If
MsgBox ("column " & i & " " & v)
End If
Next
Next
MsgBox (s)
End Sub
 
R

Ron Coderre

Not that this is better than the VBA solution posted.....
but, since you posted in the worksheet functions group,
and I felt like a challenge...
try this:

With your posted list in A1:H7

This formula locates the duplicate items in the grid
A10:
=LARGE(INDEX((FREQUENCY(($A$1:$H$7+COLUMN($A$1:$H$7)*1000),($A$1:$H$7+COLUMN($A$1:$H$7)*1000))>1)*ROW($A$1:INDEX($A:$A,COUNT($A$1:$H$7)+1)),0),COLUMNS($A$10:A10))

Copy that formula across to the right, 10 columns or so

This formula translates the location reference to an item in the grid
A11: =INDEX($A$1:$H$7,CEILING(A10/8,1),MOD(A10-1,8)+1)
Copy that formula across to the right also

I hope that helps.
***********
Regards,
Ron

XL2002, WinXP
 
T

T. Valko

Assuming "data" is in the range A1:H7.

Array entered:

=IF(ISERROR(SMALL(IF($A1:$H6=$A2:$H7,$A1:$H6),COLUMNS($A:A))),"",SMALL(IF($A1:$H6=$A2:$H7,$A1:$H6),COLUMNS($A:A)))

Copy across until you get blanks.

Biff
 
T

T. Valko

Well, maybe not!

That formula works ok on the sample you posted but when I put it through the
"wringer" it chokes!

For example: (I guess this is possible?):

100...101
100...101
101...110
101...120
101...107

Biff

T. Valko said:
Assuming "data" is in the range A1:H7.

Array entered:

=IF(ISERROR(SMALL(IF($A1:$H6=$A2:$H7,$A1:$H6),COLUMNS($A:A))),"",SMALL(IF($A1:$H6=$A2:$H7,$A1:$H6),COLUMNS($A:A)))

Copy across until you get blanks.

Biff
 
S

Sam via OfficeKB.com

Hi Ron,

Thank you for your time and assistance. Unfortunately, I am not getting the
expected results. I receive #N/A in the cells using this Formula:
=LARGE(INDEX((FREQUENCY(($A$1:$H$7+COLUMN($A$1:$H$7)*1000),($A$1:$H$7+COLUMN($A$1:$H$7)*1000))>1)*ROW($A$1:INDEX($A:$A,COUNT($A$1:$H$7)+1)),0),COLUMNS($A$10:A10))
This formula locates the duplicate items in the grid A10:
Copy that formula across to the right, 10 columns or so

My Data starts in Column "D", Row "2". Row "1" has Text Labels. I think I've
made the necessary adjustments for that but I'm still getting #N/A.

Further help appreciated.

Cheers,
Sam

Ron said:
Not that this is better than the VBA solution posted.....
but, since you posted in the worksheet functions group,
and I felt like a challenge...
try this:
With your posted list in A1:H7
This formula locates the duplicate items in the grid
A10:
=LARGE(INDEX((FREQUENCY(($A$1:$H$7+COLUMN($A$1:$H$7)*1000),($A$1:$H$7+COLUMN($A$1:$H$7)*1000))>1)*ROW($A$1:INDEX($A:$A,COUNT($A$1:$H$7)+1)),0),COLUMNS($A$10:A10))
Copy that formula across to the right, 10 columns or so
 
R

Ron Coderre

Not sure why you're getting errors.....

I used your posted data table, beginning in A1
Maybe you have column headings in Row_1?

If that's the case and the data range is in A2:H8
then these are the formulas

A11:
=LARGE(INDEX((FREQUENCY(($A$2:$H$8+COLUMN($A$2:$H$8)*1000),($A$2:$H$8+COLUMN($A$2:$H$8)*1000))>1)*ROW($A$1:INDEX($A:$A,COUNT($A$2:$H$8)+1)),0),COLUMNS($A$11:A11))

A12: =INDEX($A$2:$H$8,CEILING(A11/8,1),MOD(A11-1,8)+1)

Does that help?
***********
Regards,
Ron

XL2002, WinXP
 
S

Sam via OfficeKB.com

Hi Ron,

Thanks for reply. Even with Sample Data starting in cell A1 and using your
original version of the Formula I still get #N/A?

Ron said:
Not sure why you're getting errors.....

If anything comes to mind would appreciate further help.
I used your posted data table, beginning in A1
Maybe you have column headings in Row_1?

Yes, I just mentioned in my previous post my Data starts in Column "D", Row
"2". Row "1" has Text Labels. I think I've made the necessary adjustments for
that but I'm still getting #N/A.
If that's the case and the data range is in A2:H8
then these are the formulas

A12: =INDEX($A$2:$H$8,CEILING(A11/8,1),MOD(A11-1,8)+1)
Does that help?
***********
Regards,
Ron

XL2002, WinXP

Cheers,
Sam
 
R

Ron Coderre

The issue must be data related. Are there Blanks? Text?
Those are the only exceptions that throw errors in my testing.

With the data in A2:H11, this formula is durable against blanks, but not text

A11:
=LARGE(INDEX((FREQUENCY(($A$2:$H$8+COLUMN($A$2:$H$8)*1000),($A$2:$H$8+COLUMN($A$2:$H$8)*1000))>1)*ROW($A$1:INDEX($A:$A,ROWS($A$2:$H$8)*COLUMNS($A$2:$H$8)+1)),0),COLUMNS($A$11:A11))

Does that help?
or.... do you see anything else that may be an issue?

***********
Regards,
Ron

XL2002, WinXP
 
S

Sam via OfficeKB.com

Hi Ron,

Thanks very much for reply and further input.

Ron said:
The issue must be data related. Are there Blanks? Text?
No Blanks, text only in Row "1" .
Those are the only exceptions that throw errors in my testing.
With the data in A2:H11, this formula is durable against blanks, but not text

No text, although I did have a problem copying back my original Sample Data
using Data Text to Columns which created the #N/A errors but sorted now.

However, regarding my Sample Data and the Expected Results, I've noticed that
your Formula picks out Numeric Value 102 as a consecutive duplicate value in
the SAME column. It is a duplicate in the same column but NOT a consecutive
duplicate as described in my original post. It should not be included in the
results.
A11:
=LARGE(INDEX((FREQUENCY(($A$2:$H$8+COLUMN($A$2:$H$8)*1000),($A$2:$H$8+COLUMN($A$2:$H$8)*1000))>1)*ROW($A$1:INDEX($A:$A,ROWS($A$2:$H$8)*COLUMNS($A$2:$H$8)+1)),0),COLUMNS($A$11:A11))
Does that help?
or.... do you see anything else that may be an issue?

Numeric Value 102 is NOT a consecutive duplicate as described in my original
post. However, the Formula does incorrectly return Numeric Value 102. I think
this could be part of the problem and solution.
***********
Regards,
Ron
XL2002, WinXP

Cheers,
Sam
 
R

Ron Coderre

Well, the formulas didn't get any prettier, but....I *think* this works.....

A11:
=LARGE(INDEX((FREQUENCY((($A$2:$H$8=$A$3:$H$9)*($A$2:$H$8+COLUMN($A$2:$H$8)*1000)),($A$2:$H$8+COLUMN($A$2:$H$8)*1000))>=1)*ROW($A$1:INDEX($A:$A,ROWS($A$2:$H$8)*COLUMNS($A$2:$H$8)+1)),0),COLUMNS($A$11:A11))

A12: =IF(A11,INDEX($A$2:$H$8,CEILING(A11/8,1),MOD(A11-1,8)+1),"")

Are we done yet?

***********
Regards,
Ron

XL2002, WinXP
 
R

Ron Coderre

Done?....not quite. The previous formula calc'd consecutive blanks as dupes.

This fixes that:
A11:
=LARGE(INDEX((FREQUENCY((($A$2:$H$7<>0)*($A$2:$H$7=$A$3:$H$8)*($A$2:$H$7+COLUMN($A$2:$H$7)*1000)),($A$2:$H$7+COLUMN($A$2:$H$7)*1000))>=1)*ROW($A$1:INDEX($A:$A,ROWS($A$2:$H$7)*COLUMNS($A$2:$H$7)+1)),0),COLUMNS($A$11:A11))

How're we doing?

***********
Regards,
Ron

XL2002, WinXP
 
T

T. Valko

It's picking up the 100 in A7.

Biff

Ron Coderre said:
Done?....not quite. The previous formula calc'd consecutive blanks as
dupes.

This fixes that:
A11:
=LARGE(INDEX((FREQUENCY((($A$2:$H$7<>0)*($A$2:$H$7=$A$3:$H$8)*($A$2:$H$7+COLUMN($A$2:$H$7)*1000)),($A$2:$H$7+COLUMN($A$2:$H$7)*1000))>=1)*ROW($A$1:INDEX($A:$A,ROWS($A$2:$H$7)*COLUMNS($A$2:$H$7)+1)),0),COLUMNS($A$11:A11))

How're we doing?

***********
Regards,
Ron

XL2002, WinXP
 
S

Sam via OfficeKB.com

Hi Ron,

Using the Sample Data the results do not tie up with the Expected Results -
Now Numeric Value 100 is being listed.

Expected Results: Unique Consecutive Duplicate Returned across Single Row in
ascending order.
101 107 170 280 420 430

Column 1 = 101
Column 3 = 107, 170
Column 6 = 280, 430
Column 7 = 420


Ron said:
Done?....not quite. The previous formula calc'd consecutive blanks as dupes.
This fixes that:
A11:
=LARGE(INDEX((FREQUENCY((($A$2:$H$7<>0)*($A$2:$H$7=$A$3:$H$8)*($A$2:$H$7+COLUMN($A$2:$H$7)*1000)),($A$2:$H$7+COLUMN($A$2:$H$7)*1000))>=1)*ROW($A$1:INDEX($A:$A,ROWS($A$2:$H$7)*COLUMNS($A$2:$H$7)+1)),0),COLUMNS($A$11:A11))
How're we doing?

Not quite there, yet.
***********
Regards,
Ron
XL2002, WinXP

Cheers,
Sam
 
R

Ron Coderre

OK....Here's the latest in a series of final formulas : \

A11:
=LARGE(INDEX((FREQUENCY((($A$2:$H$7<>0)*($A$2:$H$7=$A$3:$H$8)*($A$2:$H$7+COLUMN($A$2:$H$7)*1000)),($A$2:$H$7+COLUMN($A$2:$H$7)*1000)+($A$2:$H$7<>$A$3:$H$8)*9999)>=1)*ROW($A$1:INDEX($A:$A,ROWS($A$2:$H$7)*COLUMNS($A$2:$H$7)+1)),0),COLUMNS($A$11:A11))

Copied across yields these results:
420 170 280 101 430 107

In ascending order that would be:
101 107 170 280 420 430

Dare I ask?

***********
Regards,
Ron

XL2002, WinXP
 
S

Sam via OfficeKB.com

Hi Ron,

Thank you very much for persevering.

Ron said:
OK....Here's the latest in a series of final formulas : \

Copied across yields these results:
420 170 280 101 430 107

This is Great!
In ascending order that would be:
101 107 170 280 420 430
Yes,

Dare I ask?

Can the Formula actually list them in ascending order?
***********
Regards,
Ron
XL2002, WinXP

Cheers,
Sam
 
D

Domenic

Assuming that A2:H8 contains the data, try the following...

J2:

=SUM(IF(FREQUENCY(IF(A2:H7=A3:H8,A2:H7),IF(A2:H7=A3:H8,A2:H7)),1))

....confirmed with CONTROL+SHIFT+ENTER

K2:

leave empty

L2, copied across:

=IF(COLUMNS($L$2:L2)<=$J$2,MIN(IF(ISNA(MATCH($A$2:$H$7,$K$2:K2,0)),IF($A$
2:$H$7=$A$3:$H$8,$A$2:$H$7))),"")

....confirmed with CONTROL+SHIFT+ENTER

Hope this helps!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top