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 |
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. |
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 |
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 |
Random Generation
Thanks
|
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 |
All times are GMT +1. The time now is 09:40 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com