Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default random numbers from list box

Hi Everyone,
I want to make a list,list items are numbers from 1 to 20. each tim i
click commandbutton i want two random unique items from list to
display textbox1 and textbox2. so for the next click those two items
should remove from the list.Is that possible to do without function
method? I just need one simple code in my userform.
Thank you in advance
Baha
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default random numbers from list box

Hi,

Store you numbers on a worksheet with this

Private Sub UserForm_Initialize()
With Sheets("Sheet1").Range("A1")
.Value = 1
.DataSeries Rowcol:=xlColumns, Type:=xlLinear, _
Date:=xlDay, Step:=1, Stop:=20, Trend:=False
End With
End Sub

The attach this code to your button

Private Sub CommandButton1_Click()
If WorksheetFunction.Count(Sheets("Sheet1").Range("A1 :A20")) < 2 Then
MsgBox "Not enough values left"
Exit Sub
End If

Do
Mycell = Int((20 - 1 + 1) * Rnd + 1)
FoundVal = Sheets("Sheet1").Range("A" & Mycell).Value
Sheets("Sheet1").Range("A" & Mycell).Value = ""
Loop Until FoundVal < ""
TextBox1.Text = FoundVal

Do
Mycell = Int((20 - 1 + 1) * Rnd + 1)
FoundVal = Sheets("Sheet1").Range("A" & Mycell).Value
Sheets("Sheet1").Range("A" & Mycell).Value = ""
Loop Until FoundVal < ""
TextBox2.Text = FoundVal
End Sub

Mike



" wrote:

Hi Everyone,
I want to make a list,list items are numbers from 1 to 20. each tim i
click commandbutton i want two random unique items from list to
display textbox1 and textbox2. so for the next click those two items
should remove from the list.Is that possible to do without function
method? I just need one simple code in my userform.
Thank you in advance
Baha
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default random numbers from list box

Thanks Mike,
I absulatelly whant I want. Thank you very much for the help.
Baha
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
Unique random numbers from list Matt Excel Discussion (Misc queries) 3 January 23rd 08 09:36 PM
Applying random changes to a list of numbers [email protected] Excel Discussion (Misc queries) 10 September 21st 07 07:45 PM
Random list (1-45) without repeating numbers? Hayes Excel Worksheet Functions 1 November 21st 04 10:01 PM
Random Numbers from list Cesar Zapata[_2_] Excel Programming 1 April 6th 04 03:47 PM


All times are GMT +1. The time now is 01:31 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"