Extracting number from a range randomly

Goalexcel

Board Regular
Joined
Dec 28, 2020
Messages
101
Office Version
  1. 2016
Platform
  1. Windows
Hello Expert, please kindly advise what is the best method to extract numbers from a range randomly
I have a series of numbers in the range of A1 to T16. I would like to extract 3 differents numbers from each columns, and place them in column A21, B21so on. I wonder. if there is a way to do that easily.
 
Thank you Mr.Peter, for you attention and time.
Please kindly let me give the result when I run the code
1. Every time when we choose 4 number also need to change the color.
Sometime they color from row A21 and missing color above row.
2. For first time choose 4 numbers, second time is repeated the numbers. No need to repeat numbers.
3. The point that you mention in your post, Still choosing from row A4 leaving 2 rows without choosing.,
Here the result
1637821820205.png
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I don't understand. Suppose we have the data below and 4 was chosen and the results shown. How could we proceed if the code was run again and 4 was gain chosen? There is not 4 consecutive numbers available.

Goalexcel TestPicknumbers.xlsm
A
1Sect 1
21101
31102
41103
51104
61105
71106
81107
91108
101109
111110
12
13
14
15
16
17
18
19
20Sect 1
211104
221105
231106
241107
25
26
Group 1
 
Upvote 0
I don't understand. Suppose we have the data below and 4 was chosen and the results shown. How could we proceed if the code was run again and 4 was gain chosen? There is not 4 consecutive numbers available.

Goalexcel TestPicknumbers.xlsm
A
1Sect 1
21101
31102
41103
51104
61105
71106
81107
91108
101109
111110
12
13
14
15
16
17
18
19
20Sect 1
211104
221105
231106
241107
25
26
Group 1
Please the above image numbers start A2 to A17, sometimes A20, always changes, never until A11.
Choose for example A2:A5, B6:B9, next choose will be A9:A12, next will be A13:A16 with different colors.
 
Upvote 0
Please the above image numbers start A2 to A17, sometimes A20, always changes, never until A11.
Choose for example A2:A5, B6:B9, next choose will be A9:A12, next will be A13:A16 with different colors.
I don't think that you are understanding my queries.
Your choices are very 'convenient'. As I understand it the choices are supposed to be random. So what could possibly happen here for the third choice if 4 is chosen? There are not 4 consecutive numbers any more.

Goalexcel TestPicknumbers.xlsm
A
1Sect 1
21101
31102
41103
51104
61105
71106
81107
91108
101109
111110
121111
131112
141113
151114
161115
171116
18
19
20Sect 1
211104
221105
231106
241107
251111
261112
271113
281114
29
Group 1
 
Upvote 0
I don't think that you are understanding my queries.
Your choices are very 'convenient'. As I understand it the choices are supposed to be random. So what could possibly happen here for the third choice if 4 is chosen? There are not 4 consecutive numbers any more.

Goalexcel TestPicknumbers.xlsm
A
1Sect 1
21101
31102
41103
51104
61105
71106
81107
91108
101109
111110
121111
131112
141113
151114
161115
171116
18
19
20Sect 1
211104
221105
231106
241107
251111
261112
271113
281114
29
Group 1
Good day @Peter_SSs , sorry I am not clear.
If possible to follow these step in choose 4 consecutive number, see below image: first choose 4 numbers in yellow, second choose 4 numbers in green, third choose
4 numbers in blue. Choose will be top rows, second will be lower rows, third in the middle row.
Please code apply from sheet1 until count sheet to the end, and row A until count end.
1637861840258.png
 
Upvote 0
Are the choices still supposed to be random?

Choose will be top rows, second will be lower rows, third in the middle row.
How exactly do you define "top rows", "lower rows" and "middle rows"?
 
Upvote 0
Are the choices still supposed to be random?


How exactly do you define "top rows", "lower rows" and "middle rows"?
Sorry, not send clear post. Please check the image , need consecutive numbers choose 4 numbers in yellow, 4 numbers in green and go on.
what we can use top rows = first 4 rows A2:A5, lower rows = A14:A17, middle rows= A6:A9, next final rows=A10:A13
 
Upvote 0
So it is always 4 numbers now and it is not a random choice of rows?
It is always rows 2:5 then 14;17 then 6:9 then 10:13?
 
Upvote 0
So it is always 4 numbers now and it is not a random choice of rows?
It is always rows 2:5 then 14;17 then 6:9 then 10:13?
Yes Sir, after I use the code, I am going to copy this number in another form, and it's going to choose only one number manually. That's the reason I need only 4 consecutive number until all number have been choose.
 
Upvote 0
It is always rows 2:5 then 14;17 then 6:9 then 10:13?

I am not really convinced but given my question and your answer, try this. At the moment it only works on the active sheet and column A. If it is what you actually want then it can be extended to other columns and sheets if required.

VBA Code:
Sub List4()
  Dim PrevRuns As Long, fr As Long
  Dim Clrs As Variant, FirstRows As Variant
  
  Clrs = Array(vbYellow, vbBlue, vbGreen, vbCyan)
  FirstRows = Array(2, 14, 6, 10)
  PrevRuns = (Range("A" & Rows.Count).End(xlUp).CurrentRegion.Columns(1).SpecialCells(xlConstants).Count - 1) / 4
  If PrevRuns < 4 Then
    With Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(4)
      .Value = Range("A" & FirstRows(LBound(FirstRows) + PrevRuns)).Resize(4).Value
      .Interior.Color = Clrs(LBound(Clrs) + PrevRuns)
    End With
    Range("A" & FirstRows(LBound(FirstRows) + PrevRuns)).Resize(4).Interior.Color = Clrs(LBound(Clrs) + PrevRuns)
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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