Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default generate a random list with 3 options

Excel 2002

I am trying to generate a random list of three options "Poor", "Average",
"Good"

I do not want these numbers to change once they have been generated as they
will drive further options.

Tried to use something below and then use Vlookup to get the appropraite
response but its not what I am after.

Sub Generate_Year()
Dim i As Integer

For i = 1 To 100

With Worksheets("Year")
..Cells(3 + i, 1) = "=RANDBETWEEN(1,3)"
End With
Next i

End sub

I did try
..Cells(3 + i, 1) = Application.WorksheetFunction.RANDBETWEEN(1,3)
but it didn't work.

Any suggestions would be greatley appreciated.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default generate a random list with 3 options

Doing this once?

Fill range with =INT(RAND() *3) + 1

Copy, PasteSpecial as values


"David Adamson" wrote in message
...
Excel 2002

I am trying to generate a random list of three options "Poor", "Average",
"Good"

I do not want these numbers to change once they have been generated as

they
will drive further options.

Tried to use something below and then use Vlookup to get the appropraite
response but its not what I am after.

Sub Generate_Year()
Dim i As Integer

For i = 1 To 100

With Worksheets("Year")
.Cells(3 + i, 1) = "=RANDBETWEEN(1,3)"
End With
Next i

End sub

I did try
.Cells(3 + i, 1) = Application.WorksheetFunction.RANDBETWEEN(1,3)
but it didn't work.

Any suggestions would be greatley appreciated.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default generate a random list with 3 options

Hmmm.... I get #NAME? for =RANDBETWEEN(1,3) or any numbers even tho used
example found in in Help. XL2002, SP2, Win2K Pro. Curious.

"David Adamson" wrote in message
...
Excel 2002

I am trying to generate a random list of three options "Poor", "Average",
"Good"

I do not want these numbers to change once they have been generated as

they
will drive further options.

Tried to use something below and then use Vlookup to get the appropraite
response but its not what I am after.

Sub Generate_Year()
Dim i As Integer

For i = 1 To 100

With Worksheets("Year")
.Cells(3 + i, 1) = "=RANDBETWEEN(1,3)"
End With
Next i

End sub

I did try
.Cells(3 + i, 1) = Application.WorksheetFunction.RANDBETWEEN(1,3)
but it didn't work.

Any suggestions would be greatley appreciated.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default generate a random list with 3 options

You might not have the Analysis Tool Pack installed?



"Bob Kilmer" wrote in message
...
Hmmm.... I get #NAME? for =RANDBETWEEN(1,3) or any numbers even tho used
example found in in Help. XL2002, SP2, Win2K Pro. Curious.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default generate a random list with 3 options

I have ended up creating this but can anyone suggest anything better?

---------------

Sub Generate_Year()
Dim i As Integer
Dim value As Long
Dim Data_Options As Range
Dim result As String

'set Vlookup range
With Worksheets("Options")
Set Data_Options = .Range("a4:b6")
End With

'create random numbers between 1 and 3
For i = 1 To 100
With Worksheets("Year")
..Cells(3 + i, 1) = Rnd() * (3 - 1) + 1

End With

'change random numbers to whole numbers
With Worksheets("Year")
value = .Cells(3 + i, 1)
value = Application.WorksheetFunction.Round(value, 0)
..Cells(3 + i, 1) = value
End With

'lookup up value and return name
With Worksheets("Year")
value = .Cells(3 + i, 1)
result = Application.WorksheetFunction.VLookup(value, Data_Options, 2, 0)
..Cells(3 + i, 1) = result
End With

Next i

End Sub




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default generate a random list with 3 options

Sub AAA()
Dim varr(1 To 3)
varr(1) = "Poor"
varr(2) = "Average"
varr(3) = "Good"
For i = 1 To 100
With Worksheets("Year")
..Cells(3 + i, 1) = varr(Int(Rnd() * 3 + 1))
End With
Next

End Sub

--
Regards,
Tom Ogilvy



"David Adamson" wrote in message
...
I have ended up creating this but can anyone suggest anything better?

---------------

Sub Generate_Year()
Dim i As Integer
Dim value As Long
Dim Data_Options As Range
Dim result As String

'set Vlookup range
With Worksheets("Options")
Set Data_Options = .Range("a4:b6")
End With

'create random numbers between 1 and 3
For i = 1 To 100
With Worksheets("Year")
.Cells(3 + i, 1) = Rnd() * (3 - 1) + 1

End With

'change random numbers to whole numbers
With Worksheets("Year")
value = .Cells(3 + i, 1)
value = Application.WorksheetFunction.Round(value, 0)
.Cells(3 + i, 1) = value
End With

'lookup up value and return name
With Worksheets("Year")
value = .Cells(3 + i, 1)
result = Application.WorksheetFunction.VLookup(value, Data_Options, 2, 0)
.Cells(3 + i, 1) = result
End With

Next i

End Sub




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default generate a random list with 3 options

Thanks for that Tom


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 can I generate a list of random dates from dates I specify JJ TUMIA Excel Worksheet Functions 2 August 8th 08 12:23 PM
Generate random number from a list Arnie Excel Worksheet Functions 6 November 7th 06 07:55 AM
Need to generate random values from a list Sumeet Benawra Excel Discussion (Misc queries) 2 July 13th 06 12:13 PM
generate a random number and use if function to generate new data Dogdoc1142 Excel Worksheet Functions 4 April 26th 06 03:44 AM
How to generate a random list of weekDAYS between two dates? Yanzel Muniz Excel Worksheet Functions 1 September 22nd 05 12:45 AM


All times are GMT +1. The time now is 04:15 AM.

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"