Extract selected number and move them into another locations

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,</SPAN></SPAN>

I got lottery results in the cells D6:J1000, and in the cells C6:C1000 I have numbers from 1 to 50.</SPAN></SPAN>

In the area D1:J3 where I want to put the number, which I want to extract, could be any between 1 to 50 and copy past that all rows in the columns M:T the example below is shown with 5 numbers, once these numbers are copy paste in the column M:T I want column "M" number could be colour with alternate colour as shown </SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQRST
11781012
2
3
4
5Numbersn1n2n3n4n5*1*2Numbersn1n2n3n4n5*1*2
613610639316101361063931610
723533264053812103044118
81210304411813621106962
944338191046111143849626106
1052303843467219152238102
1182710304712981133237144817
12101540244838291271444151172
1312293223151711350423934119
1413621106962132351749551
15746322734148126341337210
1679613283745746322734148
1773149282035279613283745
185322501037610731492820352
195321314393039721114132118
20542322325371117243719283663
219135053315911726452473795
2283772813411108271030471298
235923401614158377281341110
2449142381718115013402101
2532643121409681943441245105
2627105443410210154024483829
27214492119245111038291048143
282154912264258122932231517
2924336124219851263026481267
302425193613111212188443384
31223252491669
322319409552
33143849626106
3419152238102
351133237144817
361271444151172
37163243263417210
3816104217323125
391642528543611
401823348243837
41184548403432101
4218402262749105
43203128421571011
44213227393615310
452041930144549
4621371734162396
479462713432548
481263026481267
4915731392333610
5018264919453525
5121213542144379
5211350423934119
5324311827784
54132351749551
5541119392827310
565433732264954
578115013402101
581038291048143
591212188443384
60126341337210
61721114132118
627243719283663
63726452473795
645134910453112
65540265012142
6652746382826
679191624373527
6881943441245105
695155036228112
70434374626248
7132265253475
72223145372384
7324893028178
742294213163568
752504016328211
7624512342430710
77228411171513
Sheet1


Thank you all</SPAN></SPAN>

Excel 2000</SPAN></SPAN>
Regards,</SPAN>
Moti</SPAN></SPAN>
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG18Jul51
[COLOR="Navy"]Dim[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Q [COLOR="Navy"]As[/COLOR] Variant, Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Dic [COLOR="Navy"]As[/COLOR] Object
Ray = Cells(5, 3).CurrentRegion
[COLOR="Navy"]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare

[COLOR="Navy"]For[/COLOR] n = 2 To UBound(Ray, 1)
    [COLOR="Navy"]If[/COLOR] Not Dic.exists(Ray(n, 1)) [COLOR="Navy"]Then[/COLOR]
        ReDim nray(1 To 7, 1 To 1)
            [COLOR="Navy"]For[/COLOR] Ac = 2 To UBound(Ray, 2)
                nray(Ac - 1, 1) = Ray(n, Ac)
            [COLOR="Navy"]Next[/COLOR] Ac
            Dic.Add Ray(n, 1), nray
        [COLOR="Navy"]Else[/COLOR]
          Q = Dic(Ray(n, 1))
          ReDim Preserve Q(1 To 7, 1 To UBound(Q, 2) + 1)
            [COLOR="Navy"]For[/COLOR] Ac = 2 To UBound(Ray, 2)
                Q(Ac - 1, UBound(Q, 2)) = Ray(n, Ac)
            [COLOR="Navy"]Next[/COLOR] Ac
           Dic(Ray(n, 1)) = Q
            
        [COLOR="Navy"]End[/COLOR] If
   
[COLOR="Navy"]Next[/COLOR] n

[COLOR="Navy"]Dim[/COLOR] K [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] col [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
c = 6: col = 38

[COLOR="Navy"]Set[/COLOR] Rng = Range("D1:J3")
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Dic.exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
        col = IIf(col = 6, 38, 6)
        Cells(c, "M").Resize(UBound(Dic(Dn.Value), 2)) = Dn.Value
        Cells(c, "M").Resize(UBound(Dic(Dn.Value), 2)).Interior.ColorIndex = col
        Cells(c, "N").Resize(UBound(Dic(Dn.Value), 2), 7) = Application.Transpose(Dic(Dn.Value))
        c = c + UBound(Dic(Dn.Value), 2)
    [COLOR="Navy"]End[/COLOR] If

[COLOR="Navy"]Next[/COLOR] Dn

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Solution
Try this:-
Code:
[COLOR=navy]Sub[/COLOR] MG18Jul51
[COLOR=navy]Dim[/COLOR] Ray [COLOR=navy]As[/COLOR] Variant, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Q [COLOR=navy]As[/COLOR] Variant, Ac [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Dic [COLOR=navy]As[/COLOR] Object
Ray = Cells(5, 3).CurrentRegion
[COLOR=navy]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare

[COLOR=navy]For[/COLOR] n = 2 To UBound(Ray, 1)
    [COLOR=navy]If[/COLOR] Not Dic.exists(Ray(n, 1)) [COLOR=navy]Then[/COLOR]
        ReDim nray(1 To 7, 1 To 1)
            [COLOR=navy]For[/COLOR] Ac = 2 To UBound(Ray, 2)
                nray(Ac - 1, 1) = Ray(n, Ac)
            [COLOR=navy]Next[/COLOR] Ac
            Dic.Add Ray(n, 1), nray
        [COLOR=navy]Else[/COLOR]
          Q = Dic(Ray(n, 1))
          ReDim Preserve Q(1 To 7, 1 To UBound(Q, 2) + 1)
            [COLOR=navy]For[/COLOR] Ac = 2 To UBound(Ray, 2)
                Q(Ac - 1, UBound(Q, 2)) = Ray(n, Ac)
            [COLOR=navy]Next[/COLOR] Ac
           Dic(Ray(n, 1)) = Q
            
        [COLOR=navy]End[/COLOR] If
   
[COLOR=navy]Next[/COLOR] n

[COLOR=navy]Dim[/COLOR] K [COLOR=navy]As[/COLOR] Variant
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, c [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] col [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
c = 6: col = 38

[COLOR=navy]Set[/COLOR] Rng = Range("D1:J3")
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
    [COLOR=navy]If[/COLOR] Dic.exists(Dn.Value) [COLOR=navy]Then[/COLOR]
        col = IIf(col = 6, 38, 6)
        Cells(c, "M").Resize(UBound(Dic(Dn.Value), 2)) = Dn.Value
        Cells(c, "M").Resize(UBound(Dic(Dn.Value), 2)).Interior.ColorIndex = col
        Cells(c, "N").Resize(UBound(Dic(Dn.Value), 2), 7) = Application.Transpose(Dic(Dn.Value))
        c = c + UBound(Dic(Dn.Value), 2)
    [COLOR=navy]End[/COLOR] If

[COLOR=navy]Next[/COLOR] Dn

[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
Wow Mick, the macro result at a glance, result stored as request.</SPAN></SPAN>

I appreciate a lot so kind of your help and time to solve this request.
</SPAN></SPAN>

Kind Regards,
</SPAN>
Moti :-D
</SPAN></SPAN>
 
Upvote 0
If the number of entries in D1:J3 might be fewer than the entries when the macro was previously run, need to add code that first clears the data in M:T and the fill colors in column M.
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,973
Members
452,540
Latest member
haasro02

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