![]() |
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 |
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 . |
random numbers from list box
Thanks Mike,
I absulatelly whant I want. Thank you very much for the help. Baha |
All times are GMT +1. The time now is 07:11 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com