Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default strange randomization

All you need to do to use the code is:

'In the VBA Editor, click on
'ToolsReferencesMicrosoft Scripting RuntimeOK

then copy and paste my code into a standard module


"William Benson" wrote:

Thanks, will look it up and see if there is a way I can use it.

"cush" wrote in message
...
Further:
I am not totally sure of this but I think the Collection object is part of
Excel's object model, whereas Dictionary is not and requires a reference
to
MS Scripting Runtime (a dll) if you want to write code using this object.
The end user is NOT required to have such a reference.

Also, the properties and methods are a little different.
Google on Dictionary for more info.

"William Benson" wrote:

Cush,

I haven't heard of dictionary, can you tell me how dictionary differs
from
collection different?

This line: Uniques(i) = oCell.Value

is going to mean a value gets entered in the uniques column whether or
not
it had occurred prior, right?

Sorry, it is late for me, I may not be thinking right.
"cush" wrote in message
...
If I were doing this I would first insert a col B (later to be hidden)
where
I would consolidate all the data from colA (getting rid of blanks and
duplicates) with the following macro:

Sub CreateUniqueList
'Requires a reference to MS Scripting Runtime
'In the VBA Editor, click on
'ToolsReferencesMicrosoft Scripting Runtime
''''''''''''''''''''''''''''''''''''''''''''''

Dim Dict As Scripting.Dictionary
Dim i As Integer
Dim oCell As Range
Dim Source As Range
Dim Uniques As Range

Set Source = Range("A:A")
Set Uniques = Range("B:B")

Set Dict = New Dictionary
i = 1
With Dict
For Each oCell In Source
If Not .Exists(oCell.Value) Then
If Not oCell.Value = "" Then
.Add Key:=oCell.Value, Item:=i
Uniques(i) = oCell.Value
i = i + 1

End If
End If
Next oCell
End With

Shutdown:
Set Dict = Nothing

End Sub

I would then change my original formula from A:A to B:B

=INDEX(B:B,ROUND(RAND()*COUNTA(B:B),0))

This would clean it up and avoid problems with blanks.

"William Benson" wrote:

User enters any array of numbers beginning in any cell: Example

A15 23
A16 11
A17 5
. .
. .
. .
A172 145
A173 220


Required: Formula (not VBA, but perhaps array-entered) which will:

1) return a RANDOM number from AMONG the items in the list
2) Not require that the list start, list end, or # of items in
the
list be fixed (only col A is fixed).
3) not require that the list be in ascending or descending
order
3) be entered in cell B1

I started something involving INDEX and the ROW() of the starting and
ending
item, but I want it to be more dynamic. Then I tried to use MATCH to
tell
me
the start or end values, by using 0.001 and 1,000,000 and matching
with
Match_Type = 1, or -1, but that required the items be in ascending or
descending order. So, I am stuck... can it be done?









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
Excel - randomization with certain criteria Alen Paliska Excel Worksheet Functions 3 May 16th 07 06:41 PM
Data Randomization Hannie1004 Excel Worksheet Functions 2 February 16th 06 06:50 PM
Very-2 strange Amiit Mangla Excel Discussion (Misc queries) 4 December 21st 05 12:26 PM
Something Strange ame9 Setting up and Configuration of Excel 2 July 5th 05 10:31 PM
Randomization of Multiple Columns and Sequences Sandy Pasdak Excel Programming 1 July 30th 03 04:54 AM


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