Rearrange filtering data by "same number" in all the 5 positions

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Hello,

Sheet1... has data sample as data received in original format.

I want to have data filtered by the "same number" in all the 5 positions as shown in the Sheet2 leaving 1 space after each of the next number (minimum from 1 to maximum 29 numbers)

For a more detail 1 image is attached showing "sheet1 original sample data". And 2nd image is showing filtering data by "same number" in all the 5 positions.

Pease suggest VBA solution

Sheet1... data sample as data received in original format.
*ABCDEFGHIJ
1
2
3
4
5n1n2n3n4n5
6123448
7134534
8145628
91471046
102781047
112781047
121241144
1358101331
141361824
1535131839
161671828
1714101923
1848111946
1928101946
2018181939
211262036
2257182030
231252132
241252132
2556162327
26916182332
271318202330
2814212446
291718192440
3057212537
3169102649
32211132650
3314182742
3425212742
3569102735
36318222732
37111222844
3815232932
39616182938
4012153035
41514283047
4213213239
43110123233
44220243246
4567123339
4623333442
47210183435
48310263544
49718303739
5023133842
511343840
52316343848
531218353845
541820353848
551821293841
561831323848
5719183948
581518293941
59918303945
60211184046
61420364041
62223284043
63611354144
64818224142
651823374142
661234248
67110234246
68910194249
691618284249
70219284249
71120414250
721823274244
7323254348
7412264450
753484450
7637254550
77610214549
78610214549
79613224549
801029304549
81412254648
821028404748
83224314850
84
85
86
87

Sheet2...Result Required data filtered by the "same number" in all the 5 positions
*ABCDEFGHIJ
1
2
3
4
5n1n2n3n4n5
614101923
713213239
8111222844
9110234246
10120414250
1112153035
12
132781047
14223284043
15224314850
16219284249
1712264450
18220243246
191262036
20211132650
211252132
22
2337254550
241361824
253484450
26316343848
2723254348
2823133842
291234248
3023333442
31310263544
32
3348111946
3414212446
351343840
36412254648
37123448
381241144
39420364041
40
4115232932
4258101331
43514283047
4457212537
451252132
4625212742
47134534
48
49610214549
5056162327
51611354144
5269102735
53145628
5467123339
55613224549
56
57610214549
582781047
591028404748
60110123233
6169102649
621029304549
6328101946
64910194249
651471046
66
671518293941
6819183948
6918181939
701718192440
711821293841
721823274244
7335131839
74211184046
75818224142
761618284249
771831323848
78916182332
791318202330
8014182742
81318222732
82718303739
8357182030
841823374142
85210183435
861820353848
87918303945
88616182938
891671828
901218353845
91
92
93

Thank you all.

I am using Excel 2000

Regards,
Moti
 

Attachments

  • Sheet1 Orignal Data.png
    Sheet1 Orignal Data.png
    74.5 KB · Views: 13
  • Sheet2 Sort Data By Numbers.png
    Sheet2 Sort Data By Numbers.png
    74.3 KB · Views: 14
Questions:
What do you mean by "filter"? I don't see any rows is being filtered.
@Akuini, True there is non-filter I don't know how to apply what I want in the post#1, sheet1 example there are 5 numbers in each row n1, n2, n3, n4 and n5

First step filter those rows have that has "number 1" in any of 5 position and copy them in sheet2 as shown in the sheet2 result (off course as all the numbers are in ascending order "number 1" will be find in only 1st position....

Now take example of "number 10" which can find in the any of 5 position from n1 to n5 filter all rows that has number 10 in any position and copy them in sheet2 under the previous numbers..... in this way I want to be filtered and copied all rows separately from number 1 to 29... hope this makes it more cleared.

Questions:
What do you mean by "same number" & "5 position"? How do you determine which one is the "same number"?
I mean it any number that fined in any row within n1 to n5... like 10 in n1, 10 in n2, 10 in n3, 10 in n4 or 10 in n5 is a same number but in different position among n1 to n5.

Hope this helps

Kind Regards,
Moti
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Still not clear to me.
In sheet2 (the result), it looks like you arrange data by groups (and separate them by a blank row), for example the first group, you highlight number "1" with red. Why the other rows that has 1 in it doesn't belong to the first group? for example row 17, 19, etc.
 
Upvote 0
Still not clear to me.
In sheet2 (the result), it looks like you arrange data by groups (and separate them by a blank row), for example the first group, you highlight number "1" with red. Why the other rows that has 1 in it doesn't belong to the first group? for example row 17, 19, etc.
@Akuini, that is exactly I want to arrange data by groups... your observation is spot on it is my big mistake copying and pasting rows manually creating an example sheet2 which is not correct I am sorry for the inconvenience I am sure you got my point view perfectly ok please help with macro to accomplish this task automatically by grouping them 1 to 29 separately giving one line space between each of the group.

Thank you in advance

Kind Regards,
Moti
 
Upvote 0
So what the correct result should look like?
@Akuini, ok here is a sheet3 with original data and sheet4 expected result filtered by group in this example there is shown only with grouped by 1, 2 and 10 but I need from 1 to 29 to be sorted.

Sheet3 Orignal Data
*ABCDEFGHIJ
1
2
3
4
5n1n2n3n4n5
6123448
7134534
8145628
91471046
102781047
112781047
121241144
1358101331
141361824
1535131839
161671828
1714101923
1848111946
1928101946
2018181939
211262036
2257182030
231252132
241252132
2556162327
26916182332
271318202330
2814212446
291718192440
3057212537
3169102649
32211132650
3314182742
3425212742
3569102735
36318222732
37111222844
3815232932
39616182938
4012153035
41514283047
4213213239
43110123233
44220243246
4567123339
4623333442
47210183435
48310263544
49718303739
5023133842
511343840
52316343848
531218353845
541820353848
551821293841
561831323848
5719183948
581518293941
59918303945
60211184046
61420364041
62223284043
63611354144
64818224142
651823374142
661234248
67110234246
68910194249
691618284249
70219284249
71120414250
721823274244
7323254348
7412264450
753484450
7637254550
77610214549
78610214549
79613224549
801029304549
81412254648
821028404748
83224314850
84
85
86
87


Sheet4 Filter Data By Groups
*ABCDEFGHIJ
1
2
3
4
5n1n2n3n4n5
6123448
7134534
8145628
91471046
101241144
111361824
121671828
1314101923
1418181939
151262036
161252132
171252132
1814212446
1914182742
20111222844
2115232932
2212153035
2313213239
24110123233
251343840
2619183948
271234248
28110234246
29120414250
3012264450
31
32123448
332781047
342781047
351241144
3628101946
371262036
381252132
391252132
40211132650
4125212742
4212153035
43220243246
4423333442
45210183435
4623133842
47211184046
48223284043
491234248
50219284249
5123254348
5212264450
53224314850
54
551471046
562781047
572781047
5858101331
5914101923
6028101946
6169102649
6269102735
63110123233
64210183435
65310263544
66110234246
67910194249
68610214549
69610214549
701029304549
711028404748
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

Thank you in advance

Kind Regards,
Moti
 

Attachments

  • Sheet3 Orignal Data.png
    Sheet3 Orignal Data.png
    72.8 KB · Views: 8
  • Sheet4 Filter Data By Groups.png
    Sheet4 Filter Data By Groups.png
    69.2 KB · Views: 8
Upvote 0
Try this:
I put the result in col L.
VBA Code:
Sub motilulla()
Dim i As Long, j As Long, k As Long, n As Long, g As Long
Dim va, vb
Dim d As Object

n = Range("E" & Rows.Count).End(xlUp).Row
va = Range("E6:I" & n)
ReDim vb(1 To UBound(va, 1) * 10, 1 To 6)


For k = 1 To 29
    
    For i = 1 To UBound(va, 1)
            For j = 1 To 5
                If va(i, j) = k Then
                    g = g + 1
                    For w = 1 To 5
                        vb(g, w) = va(i, w)
                    Next
                    vb(g, 6) = k
                    
                    Exit For
                End If
            Next
        
    Next
    g = g + 1
Next

Range("L6").Resize(g, 6) = vb

End Sub
 
Upvote 0
Solution
Try this:
I put the result in col L.
VBA Code:
Sub motilulla()
Dim i As Long, j As Long, k As Long, n As Long, g As Long
Dim va, vb
Dim d As Object

n = Range("E" & Rows.Count).End(xlUp).Row
va = Range("E6:I" & n)
ReDim vb(1 To UBound(va, 1) * 10, 1 To 6)


For k = 1 To 29
   
    For i = 1 To UBound(va, 1)
            For j = 1 To 5
                If va(i, j) = k Then
                    g = g + 1
                    For w = 1 To 5
                        vb(g, w) = va(i, w)
                    Next
                    vb(g, 6) = k
                   
                    Exit For
                End If
            Next
       
    Next
    g = g + 1
Next

Range("L6").Resize(g, 6) = vb

End Sub
Akuini, this is it absolutely amazing! You nail my viewpoint also I like the end column you added who is showing which number of group is sorted out.

I am very happy to have a solved my query more best then as I required.

Thank you so much for your interest and time you spent to solve it.

Good Luck and happy New Year 2022

Kind Regards,
Moti :)
 
Upvote 0

Forum statistics

Threads
1,214,853
Messages
6,121,935
Members
449,056
Latest member
denissimo

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