Random Numbers

  • Thread starter Thread starter robert morris
  • Start date Start date
R

robert morris

I need help with a VBA for creating NON-REPEATING random numbers between 0-9
in Col B4:B13 and Row C3:L3

Bob
 
would this macro help?

Sub cus()
Dim cell As Range

With Range("B4:B13")
..Clear
For Each cell In .Cells
repeat:
k = WorksheetFunction.RandBetween(0, 9)
If WorksheetFunction.CountIf(.Cells, k) = 0 Then
cell = k
Else
GoTo repeat
End If
Next
End With
End Sub
 
would this macro help?

Sub cus()
Dim cell As Range

With Range("B4:B13")
..Clear
For Each cell In .Cells
repeat:
k = WorksheetFunction.RandBetween(0, 9)
If WorksheetFunction.CountIf(.Cells, k) = 0 Then
cell = k
Else
GoTo repeat
End If
Next
End With
End Sub
 
Bob,
I think your requirements are a little too strict. <g>
You only allow ten unique numbers (0 to 9) and ten cells in each range.
Are you just trying to random sort all ten numbers?
--
Jim Cone
Portland, Oregon USA



"robert morris"
<[email protected]>
wrote in message

I need help with a VBA for creating NON-REPEATING random numbers between 0-9
in Col B4:B13 and Row C3:L3

Bob
 
Bob,
I think your requirements are a little too strict. <g>
You only allow ten unique numbers (0 to 9) and ten cells in each range.
Are you just trying to random sort all ten numbers?
--
Jim Cone
Portland, Oregon USA



"robert morris"
<[email protected]>
wrote in message

I need help with a VBA for creating NON-REPEATING random numbers between 0-9
in Col B4:B13 and Row C3:L3

Bob
 
Jim,

I need random numbers for BOTH Row 3 and Col B.

Have I answered your question correctly?

Bob
 
Jim,

I need random numbers for BOTH Row 3 and Col B.

Have I answered your question correctly?

Bob
 
Jarek,

Thanks, your Code works perfectly for the Column B but does not address Row 3.

Bob
 
Jarek,

Thanks, your Code works perfectly for the Column B but does not address Row 3.

Bob
 
having re-read the conditions I have to agree with Jim
they are to strict
are you trying to populate C3:L3 AND B4:B13 with random integers
ranging from 0 to 9?
if so I cannot provide a solution
or you meant to populate both ranges SEPARATELY?
 
having re-read the conditions I have to agree with Jim
they are to strict
are you trying to populate C3:L3 AND B4:B13 with random integers
ranging from 0 to 9?
if so I cannot provide a solution
or you meant to populate both ranges SEPARATELY?
 
Jarek,

Yes, populate both ranges separately. Possibly two different Codes?

I appreciate your help.

Bob
 
Jarek,

Yes, populate both ranges separately. Possibly two different Codes?

I appreciate your help.

Bob
 
Jarek,

Yes, random numbers between 0-9, Col Range B4:B13 and
random numbers between 0-9, Row Range C3:L3.

As I said, could be two codes with Buttons.

Bob
 
Jarek,

Yes, random numbers between 0-9, Col Range B4:B13 and
random numbers between 0-9, Row Range C3:L3.

As I said, could be two codes with Buttons.

Bob
 
for C3:L3

Sub cus2()
Dim cell As Range


With Range("C3:L3")
..Clear
For Each cell In .Cells
repeat:
k = WorksheetFunction.RandBetween(0, 9)
If WorksheetFunction.CountIf(.Cells, k) = 0 Then
cell = k
Else
GoTo repeat
End If
Next
End With
End Sub


then assign cus to Button1 and cus2 to Button2

is this ok?
 
for C3:L3

Sub cus2()
Dim cell As Range


With Range("C3:L3")
..Clear
For Each cell In .Cells
repeat:
k = WorksheetFunction.RandBetween(0, 9)
If WorksheetFunction.CountIf(.Cells, k) = 0 Then
cell = k
Else
GoTo repeat
End If
Next
End With
End Sub


then assign cus to Button1 and cus2 to Button2

is this ok?
 
Jarek,

Works almost perfectly. Random Numbers are perfect however, when applied, I
lose my Formatting for the "Range" on both the Col and Row. Why would this
happen?

Sorry for my delay in replying, I fell asleep.

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top