Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Doyle Brunson
 
Posts: n/a
Default randomly select value WITHOUT changing


I am using a formula to randomly select one of the values in a list.

However, the value returned by the formula changes with each
recalculation (F9), and I do not want that to happen.


IS THERE A WAY TO GENERATE A RANDOM VALUE FROM A LIST WITHOUT IT
CHANGING WITH EACH RECALCULATION?

The reason I ask is that I have combo boxes in the worksheet which
makes it recalculate whenever they are used.

PART 2: Is it possible to assign the formula to a button so that the
update only occours when it is pressed?

***
FYI formula used to formula to randomly select one of the values in a
list:
INDEX, ROUND, RAND, and COUNTA functions in the following formula:
=INDEX(A2:A7,ROUND(RAND()*COUNTA(A2:A7),0))


--
Doyle Brunson
------------------------------------------------------------------------
Doyle Brunson's Profile: http://www.excelforum.com/member.php...o&userid=19235
View this thread: http://www.excelforum.com/showthread...hreadid=398107

  #2   Report Post  
Junior Member
 
Location: Washington, DC
Posts: 16
Default

Doyle,

To my knowledge, you can't control when an Excel formula updates. You can, however, create a macro that does this. Paste the code below into VBA (ALT+F11) and it will randomly choose a number from A2:A7 and deposit the value into the currently active cell. You can link this code to a button if you like. Be sure that the sheet with the datalist is currently selected (this shouldn't be a problem if you put your button on the same page).

Here's the code:

'---------------------
Sub RandomListSelect()

ListRange = ActiveSheet.Range("A2:A7")

CountAProxy = Application.WorksheetFunction.CountA(ListRange)

ActiveCell.Value = Application.WorksheetFunction.Index(ListRange, Round(Rnd() * CountAProxy, 0))

End Sub
'---------------------

Knightly


Quote:
Originally Posted by Doyle Brunson
I am using a formula to randomly select one of the values in a list.

However, the value returned by the formula changes with each
recalculation (F9), and I do not want that to happen.


IS THERE A WAY TO GENERATE A RANDOM VALUE FROM A LIST WITHOUT IT
CHANGING WITH EACH RECALCULATION?

The reason I ask is that I have combo boxes in the worksheet which
makes it recalculate whenever they are used.

PART 2: Is it possible to assign the formula to a button so that the
update only occours when it is pressed?

***
FYI formula used to formula to randomly select one of the values in a
list:
INDEX, ROUND, RAND, and COUNTA functions in the following formula:
=INDEX(A2:A7,ROUND(RAND()*COUNTA(A2:A7),0))


--
Doyle Brunson
------------------------------------------------------------------------
Doyle Brunson's Profile: http://www.excelforum.com/member.php...o&userid=19235
View this thread: http://www.excelforum.com/showthread...hreadid=398107
  #3   Report Post  
Doyle Brunson
 
Posts: n/a
Default


It's working perfectly. Thank you for a useful macro.


--
Doyle Brunson
------------------------------------------------------------------------
Doyle Brunson's Profile: http://www.excelforum.com/member.php...o&userid=19235
View this thread: http://www.excelforum.com/showthread...hreadid=398107

  #4   Report Post  
tx12345
 
Posts: n/a
Default


Hi

I tried the macro and it kept stopping. It keeps saying "Variable not
defined" while highlighting "ListRange =" in the macro.

I have

4
7
2
14
12
16

showing in A2:A7 on a blank worksheet. Not sure where the uniqe random
number is supposed to be.


--
tx12345
------------------------------------------------------------------------
tx12345's Profile: http://www.excelforum.com/member.php...o&userid=24776
View this thread: http://www.excelforum.com/showthread...hreadid=398107

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 to randomly select from a list with condition kathyxyz Excel Worksheet Functions 5 July 27th 05 05:19 PM
Is there a way to randomly select rows in Excel? Samantha Excel Discussion (Misc queries) 4 May 12th 05 03:59 PM
How do I select multiple rows randomly in MS Excel? Varun Excel Discussion (Misc queries) 2 April 18th 05 09:10 AM
Can the computer be set to randomly select a row for a drawing? annie33 Excel Discussion (Misc queries) 1 April 8th 05 07:31 PM
Dynamic Formulas with Dynamic Ranges Ralph Howarth Excel Worksheet Functions 5 January 21st 05 09:44 AM


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