Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random numbers not using randbetween()


Hi everyone,
I have been trying repeatedly for days now to write a macro to generat
random numbers. I need to generate 23 unique numbers in 5 columns.
have found a macro that can do one column at a time but i cannot modif
this to work over the five columns.

Here is the code for you to look at:

Sub CreateRand()
Dim Nums(23)
Dim I As Integer
Dim X As Integer
Dim rng As Range
Dim c As Range
Dim Filled As Boolean

For I = 1 To 23
Nums(I) = I
Next I

Set rng = Range("f1:f23")

For Each c In rng

Do

X = Int((Rnd * 23) + 1)
If Nums(X) < 0 Then
c.Value = Nums(X)
Nums(X) = 0
Filled = True
End If
Loop Until Filled
Filled = False
Next c
End Sub
All help will be greatly received!!!!!!


Thanks, a slowly going bald Excel use

--
davehill197
-----------------------------------------------------------------------
davehill1974's Profile: http://www.excelforum.com/member.php...fo&userid=2499
View this thread: http://www.excelforum.com/showthread.php?threadid=38521

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random numbers not using randbetween()


untested, but what if you set your range to Set rng = Range("f1:j23")
instead of Set rng = Range("f1:f23")?

Good Luck


--
swatsp0p


------------------------------------------------------------------------
swatsp0p's Profile: http://www.excelforum.com/member.php...o&userid=15101
View this thread: http://www.excelforum.com/showthread...hreadid=385218

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random numbers not using randbetween()


Hi,

I have tried this and it made Excel freeze! I left it running for an
hour just to make sure.

Thanks for the reply though.
You never know i may need to just leave Excel running fr a further
hour!!!!


--
davehill1974
------------------------------------------------------------------------
davehill1974's Profile: http://www.excelforum.com/member.php...o&userid=24995
View this thread: http://www.excelforum.com/showthread...hreadid=385218

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random numbers not using randbetween()


do the random numbers need to be between 1 and 23 in each of the five
columns?


--
swatsp0p


------------------------------------------------------------------------
swatsp0p's Profile: http://www.excelforum.com/member.php...o&userid=15101
View this thread: http://www.excelforum.com/showthread...hreadid=385218

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random numbers not using randbetween()


Hi again,

Yes the numbers need to be between 1 and 23 in all five columns.

What i am doing in more depth is:

we have 23 groups and 23 activities. All of the 23 groups need to carry
out activities at random over 5 periods. So thats a total of 5
activities each. What i have got is a grid that generates the random
numbers, i then do a lookup on the numbers to get the activity I.E.
Swimming.

The source worksheet looks something like:


P1 P2 P3 P4 P5
Activity 1 15 18 5 22 21
Activity 2 13 7 16 12 6
Activity 3 14 16 18 8 22
Activity 4 7 6 15 10 20
Activity 5 18 3 4 6 11
Activity 6 1 22 19 5 12
Activity 7 19 8 23 1 18
Activity 8 2 19 8 18 9
Activity 9 10 12 9 7 5
Activity 10 20 2 11 17 8
Activity 11 9 5 3 20 10
Activity 12 23 20 17 19 4
Activity 13 21 14 13 11 15
Activity 14 22 1 10 2 3
Activity 15 11 13 21 4 16
Activity 16 17 15 1 14 23
Activity 17 6 10 7 3 1
Activity 18 16 23 22 13 7
Activity 19 3 4 12 15 19
Activity 20 4 17 6 21 14
Activity 21 8 21 2 9 17
Activity 22 5 9 20 23 13
Activity 23 12 11 14 16 2


I am using office 2003.

Hope that this helps. Dave.


--
davehill1974
------------------------------------------------------------------------
davehill1974's Profile: http://www.excelforum.com/member.php...o&userid=24995
View this thread: http://www.excelforum.com/showthread...hreadid=385218



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random numbers not using randbetween()


Hi Everyone,

This has now been sorted thnks to a nice chap from elsewhere. I
fanybody would like the answer say so and i will post it.


--
davehill1974
------------------------------------------------------------------------
davehill1974's Profile: http://www.excelforum.com/member.php...o&userid=24995
View this thread: http://www.excelforum.com/showthread...hreadid=385218

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Random numbers not using randbetween()


You need 23 numbers spread over 5 columns?

You need five columns each with 23 unique numbers ( 5 x 23 unique numbers
total)?
You need five columns each with 23 unique numbers within the individual
column (23 unique numbers total repeated 5 times)?

--
Regards,
Tom Ogilvy



"davehill1974"
wrote in message
news:davehill1974.1rsw2i_1120741584.5943@excelforu m-nospam.com...

Hi everyone,
I have been trying repeatedly for days now to write a macro to generate
random numbers. I need to generate 23 unique numbers in 5 columns. I
have found a macro that can do one column at a time but i cannot modify
this to work over the five columns.

Here is the code for you to look at:

Sub CreateRand()
Dim Nums(23)
Dim I As Integer
Dim X As Integer
Dim rng As Range
Dim c As Range
Dim Filled As Boolean

For I = 1 To 23
Nums(I) = I
Next I

Set rng = Range("f1:f23")

For Each c In rng

Do

X = Int((Rnd * 23) + 1)
If Nums(X) < 0 Then
c.Value = Nums(X)
Nums(X) = 0
Filled = True
End If
Loop Until Filled
Filled = False
Next c
End Sub
All help will be greatly received!!!!!!


Thanks, a slowly going bald Excel user


--
davehill1974
------------------------------------------------------------------------
davehill1974's Profile:

http://www.excelforum.com/member.php...o&userid=24995
View this thread: http://www.excelforum.com/showthread...hreadid=385218



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Random numbers not using randbetween()

Change F1:F23 to the first set of 23 cells (next to the activities titles)
Sub CreateRand()
Dim Nums(23)
Dim I As Integer
Dim X As Integer
Dim rng As Range
Dim c As Range
Dim Filled As Boolean

For I = 1 To 23
Nums(I) = I
Next I

Set rng = Range("f1:f23")
for i = 0 to 4
For Each c In rng.offset(0,i)

Do

X = Int((Rnd * 23) + 1)
If Nums(X) < 0 Then
c.Value = Nums(X)
Nums(X) = 0
Filled = True
End If
Loop Until Filled
Filled = False
Next c
Next i
End Sub

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...

You need 23 numbers spread over 5 columns?

You need five columns each with 23 unique numbers ( 5 x 23 unique numbers
total)?
You need five columns each with 23 unique numbers within the individual
column (23 unique numbers total repeated 5 times)?

--
Regards,
Tom Ogilvy



"davehill1974"
wrote in message
news:davehill1974.1rsw2i_1120741584.5943@excelforu m-nospam.com...

Hi everyone,
I have been trying repeatedly for days now to write a macro to generate
random numbers. I need to generate 23 unique numbers in 5 columns. I
have found a macro that can do one column at a time but i cannot modify
this to work over the five columns.

Here is the code for you to look at:

Sub CreateRand()
Dim Nums(23)
Dim I As Integer
Dim X As Integer
Dim rng As Range
Dim c As Range
Dim Filled As Boolean

For I = 1 To 23
Nums(I) = I
Next I

Set rng = Range("f1:f23")

For Each c In rng

Do

X = Int((Rnd * 23) + 1)
If Nums(X) < 0 Then
c.Value = Nums(X)
Nums(X) = 0
Filled = True
End If
Loop Until Filled
Filled = False
Next c
End Sub
All help will be greatly received!!!!!!


Thanks, a slowly going bald Excel user


--
davehill1974
------------------------------------------------------------------------
davehill1974's Profile:

http://www.excelforum.com/member.php...o&userid=24995
View this thread:

http://www.excelforum.com/showthread...hreadid=385218





  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Random numbers not using randbetween()

Hello,

I presume that no group should attend the same activity twice.

So:

Option Explicit

Public Sub gen5periods()

Dim i As Long
Dim j As Long
Dim k As Long
Dim brepeat As Boolean

Range("B2:B24").FormulaArray = "=uniqrandint(23,false)"
For i = 3 To 6
brepeat = True
Do While brepeat
Range(Cells(2, i), Cells(24, i)).FormulaArray =
"=uniqrandint(23,false)"
brepeat = False
For j = 2 To i - 1
For k = 2 To 24
If Cells(k, j).Value = Cells(k, i).Value Then
brepeat = True
End If
Next k
Next j
Loop
Next i

End Sub

My function UniqRandInt() you can find at:
http://www.sulprobil.com/html/uniqrandint.html

HTH,
Bernd
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to keep random number from changing using RANDBETWEEN? TXlimogirl Excel Worksheet Functions 6 April 3rd 23 04:41 PM
RANDBETWEEN generating numbers outside range Penny Black Excel Worksheet Functions 5 May 25th 10 10:14 PM
how can I use randbetween without repeating numbers in a set Maria Excel Worksheet Functions 7 October 30th 09 06:19 AM
Non-random numbers generated by excel's data analysis random gener Allie Excel Worksheet Functions 10 September 17th 05 06:19 AM
Non-random numbers generated by excel's data analysis random gener Harlan Grove Excel Discussion (Misc queries) 2 September 13th 05 04:06 PM


All times are GMT +1. The time now is 10:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"