Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Random Generation


Hi.

I am using VBA within Excel and have to generate the following:

4 Integers between 1 and 6 inclusive, none of which are the same.

I can only use VBA to do this.

Thanks,

lot9

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Random Generation

Take a look he

http://www.mcgimpsey.com/excel/randint.html


In article .com,
"lordofthe9" wrote:

I am using VBA within Excel and have to generate the following:

4 Integers between 1 and 6 inclusive, none of which are the same.

I can only use VBA to do this.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Random Generation

Sub AA()
Dim v(1 To 6) As Long
Dim i As Long
Dim j As Long

i = 0
Do
j = Int(Rnd() * 6 + 1)
If v(j) = 0 Then
i = i + 1
v(j) = i
End If
Loop While i < 4
j = 0
For i = 1 To 6
If v(i) < 0 Then
j = j + 1
Cells(j, 1).Value = i
End If
Next
End Sub


--
Regards,
Tom Ogilvy

"lordofthe9" wrote in message
oups.com...

Hi.

I am using VBA within Excel and have to generate the following:

4 Integers between 1 and 6 inclusive, none of which are the same.

I can only use VBA to do this.

Thanks,

lot9



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Random Generation

dim v(1 to 6) as Long
i = 0
do while i < 6
j = int(rnd()*6+1)
if v(j) = 0 then
i = i + 1
v(j) = i
end if
Next
j = 0
for i = 1 to 6
if v(i) < 0 then
j = j + 1
cells(j,1).Value = i
end if
Next


"lordofthe9" wrote in message
oups.com...

Hi.

I am using VBA within Excel and have to generate the following:

4 Integers between 1 and 6 inclusive, none of which are the same.

I can only use VBA to do this.

Thanks,

lot9



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Random Generation

Thanks



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Random Generation

you could type the numbers 1 to 6 in one column and then =rand() on the next
column; to randomize, sort by the rand() column.
A B
1| 1 =RAND()
2| 2 =RAND()
3| 3 =RAND()
4| 4 =RAND()
5| 5 =RAND()
6| 6 =RAND()

then click on B1 and click on the sort ascending button.

"lordofthe9" wrote:


Hi.

I am using VBA within Excel and have to generate the following:

4 Integers between 1 and 6 inclusive, none of which are the same.

I can only use VBA to do this.

Thanks,

lot9


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
random letter generation Ann Excel Worksheet Functions 5 May 30th 08 06:52 PM
Random List Generation carl Excel Worksheet Functions 4 May 23rd 06 02:18 PM
Random Name Generation pkbro Excel Worksheet Functions 1 June 21st 05 02:03 AM
random number generation kurtrambis Excel Worksheet Functions 1 November 1st 04 09:23 PM
random number generation nyn04[_5_] Excel Programming 3 September 22nd 04 02:13 PM


All times are GMT +1. The time now is 02:55 PM.

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

About Us

"It's about Microsoft Excel"