getting excell to pick a number from 1 to 10

tonylpcs@yahoo.co.uk

Active Member
Joined
Dec 19, 2007
Messages
379
Hi I think i have been looking at this a little wrong so maybe someone can help me?

i want excel to pick numbers from 1 to 10 in ten different rows but not numbers that have been picked before.

its a bit like setting up a ramdom lottery number picker in the sence that you want the numbers unique

so cells

a10 to a20 need to be a number between 1 and 10
then
cells b10 to b20 need to be numbers between 1 and 10 but excluding the number in the matching cell of A (I.E B2 cant equal A2 but any of the other numbers is fine,
then
cell C10 to C20 need to be numbers between 1 and 10 but not whats in cells a or b and so on.

any ideas?

thanks

Tony
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
See if you can adapt this random generator routine :

Code:
Private Sub GenerateUniqueNumbers _
(ByVal Min As Byte, ByVal Max As Byte, ByRef ar() As Variant)

    Dim bCounter As Byte
    Dim bRndValue As Byte
    
    bCounter = 1
    
    Do
        On Error Resume Next
            Randomize
            With Application.WorksheetFunction
                bRndValue = .RandBetween(Min, Max)
                Call .Match(bRndValue, ar, 0)
            End With
            If Err.Number <> 0 Then
                ar(bCounter) = bRndValue: bCounter = bCounter + 1
            End If
        Err.Clear
        DoEvents
    Loop Until ar(UBound(ar)) <> Empty

End Sub

The following will use the above routine to put unique random numbers between 1-10 in the Range("A1:J1") :

Code:
Sub Test()

    Dim RandomValues(1 To 10)

    GenerateUniqueNumbers 1, 10, RandomValues
    Range("a1:j1") = RandomValues

End Sub
 
Last edited:
Upvote 0
I do not know how to do it in excel or vb code but i done it manually
here is the result;
Excel Workbook
BCD
10172
112106
123110
13461
14528
15639
16783
17894
18957
191045
Sheet1

Is this what you want?
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,943
Latest member
Newbie4296

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