Find "Start and End" row number of the each unique pattern

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000</SPAN></SPAN>
Hi,
</SPAN></SPAN>

Column C got repeated patterns (or can be said unique patterns)
</SPAN></SPAN>
I want to list the row number of each unique set "Start row number" & the "End row number" in the column E:F
</SPAN></SPAN>

Example data
</SPAN></SPAN>


Book1
ABCDEFG
1
2
3
4PattStartEnd
5PattRow NumRow Num
60 | 0 | 0 | 0 | 0 | 0 | 268
70 | 0 | 0 | 0 | 0 | 0 | 2912
80 | 0 | 0 | 0 | 0 | 0 | 21315
90 | 0 | 0 | 0 | 0 | 1 | 11619
100 | 0 | 0 | 0 | 0 | 1 | 12023
110 | 0 | 0 | 0 | 0 | 1 | 12426
120 | 0 | 0 | 0 | 0 | 1 | 12730
130 | 0 | 0 | 0 | 0 | 2 | 03134
140 | 0 | 0 | 0 | 0 | 2 | 03538
150 | 0 | 0 | 0 | 0 | 2 | 03941
160 | 0 | 0 | 0 | 1 | 0 | 14245
170 | 0 | 0 | 0 | 1 | 0 | 14657
180 | 0 | 0 | 0 | 1 | 0 | 15868
190 | 0 | 0 | 0 | 1 | 0 | 1
200 | 0 | 0 | 0 | 1 | 1 | 0
210 | 0 | 0 | 0 | 1 | 1 | 0
220 | 0 | 0 | 0 | 1 | 1 | 0
230 | 0 | 0 | 0 | 1 | 1 | 0
240 | 0 | 0 | 0 | 2 | 0 | 0
250 | 0 | 0 | 0 | 2 | 0 | 0
260 | 0 | 0 | 0 | 2 | 0 | 0
270 | 0 | 0 | 1 | 0 | 0 | 1
280 | 0 | 0 | 1 | 0 | 0 | 1
290 | 0 | 0 | 1 | 0 | 0 | 1
300 | 0 | 0 | 1 | 0 | 0 | 1
310 | 0 | 0 | 1 | 0 | 1 | 0
320 | 0 | 0 | 1 | 0 | 1 | 0
330 | 0 | 0 | 1 | 0 | 1 | 0
340 | 0 | 0 | 1 | 0 | 1 | 0
350 | 0 | 0 | 1 | 1 | 0 | 0
360 | 0 | 0 | 1 | 1 | 0 | 0
370 | 0 | 0 | 1 | 1 | 0 | 0
380 | 0 | 0 | 1 | 1 | 0 | 0
390 | 0 | 0 | 2 | 0 | 0 | 0
400 | 0 | 0 | 2 | 0 | 0 | 0
410 | 0 | 0 | 2 | 0 | 0 | 0
420 | 0 | 1 | 0 | 0 | 0 | 1
430 | 0 | 1 | 0 | 0 | 0 | 1
440 | 0 | 1 | 0 | 0 | 0 | 1
450 | 0 | 1 | 0 | 0 | 0 | 1
460 | 0 | 1 | 0 | 0 | 0 | 1
470 | 0 | 1 | 0 | 0 | 0 | 1
480 | 0 | 1 | 0 | 0 | 0 | 1
490 | 0 | 1 | 0 | 0 | 0 | 1
500 | 0 | 1 | 0 | 0 | 0 | 1
510 | 0 | 1 | 0 | 0 | 0 | 1
520 | 0 | 1 | 0 | 0 | 0 | 1
530 | 0 | 1 | 0 | 0 | 0 | 1
540 | 0 | 1 | 0 | 0 | 0 | 1
550 | 0 | 1 | 0 | 0 | 0 | 1
560 | 0 | 1 | 0 | 0 | 0 | 1
570 | 0 | 1 | 0 | 0 | 0 | 1
580 | 0 | 2 | 0 | 0 | 0 | 0
590 | 0 | 2 | 0 | 0 | 0 | 0
600 | 0 | 2 | 0 | 0 | 0 | 0
610 | 0 | 2 | 0 | 0 | 0 | 0
620 | 0 | 2 | 0 | 0 | 0 | 0
630 | 0 | 2 | 0 | 0 | 0 | 0
640 | 0 | 2 | 0 | 0 | 0 | 0
650 | 0 | 2 | 0 | 0 | 0 | 0
660 | 0 | 2 | 0 | 0 | 0 | 0
670 | 0 | 2 | 0 | 0 | 0 | 0
680 | 0 | 2 | 0 | 0 | 0 | 0
69
70
71
Sheet1


Thank you in advance
</SPAN></SPAN>

Regards,
</SPAN>
Kishan
</SPAN></SPAN>
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG18Oct38
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Q [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] Rng = Range("C6", Range("C" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Not .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
        .Add Dn.Value, Array(Dn.Row, Dn.Row)
    [COLOR="Navy"]Else[/COLOR]
        Q = .Item(Dn.Value)
            Q(1) = Dn.Row
        .Item(Dn.Value) = Q
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
Range("E6").Resize(.Count, 2) = Application.Transpose(Application.Transpose(.items))
[COLOR="Navy"]End[/COLOR] With

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Formulas:

In E6:

=ROW(C6)

In F6:

=LOOKUP(2,1/($C$6:$C$68=INDEX($C$6:$C$68,E6-ROW($C$6)+1)),ROW($C$6:$C$68))

In E7:

=F6+1

Drag down on E7 and F6 until you start getting errors. You have then run out of data. It requires sorted data as you presented.
 
Upvote 0
Formulas:

In E6:

=ROW(C6)

In F6:

=LOOKUP(2,1/($C$6:$C$68=INDEX($C$6:$C$68,E6-ROW($C$6)+1)),ROW($C$6:$C$68))

In E7:

=F6+1

Drag down on E7 and F6 until you start getting errors. You have then run out of data. It requires sorted data as you presented.
steve the fish, tried the formula it worked

Thank you for the help

Kind Regards,
Kishan
 
Upvote 0
Try this:-
Code:
[COLOR=navy]Sub[/COLOR] MG18Oct38
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Q [COLOR=navy]As[/COLOR] Variant
[COLOR=navy]Set[/COLOR] Rng = Range("C6", Range("C" & Rows.Count).End(xlUp))
[COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
    [COLOR=navy]If[/COLOR] Not .Exists(Dn.Value) [COLOR=navy]Then[/COLOR]
        .Add Dn.Value, Array(Dn.Row, Dn.Row)
    [COLOR=navy]Else[/COLOR]
        Q = .Item(Dn.Value)
            Q(1) = Dn.Row
        .Item(Dn.Value) = Q
    [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR]
Range("E6").Resize(.Count, 2) = Application.Transpose(Application.Transpose(.items))
[COLOR=navy]End[/COLOR] With

[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
MickG, I liked the macro solution it worked fine!! It is an easy and also quick and accurate while working with enormous data </SPAN></SPAN>

Thank you for your time and help
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Kishan
</SPAN></SPAN>
:)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,048
Messages
6,122,862
Members
449,097
Latest member
dbomb1414

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