excel VBA 點寫 random number?

2011-08-21 4:41 am
我想從1-49個號碼入面
抽6個數字出黎買六合彩
所以數字唔可以重覆
而每個number出現既probablity要一樣

假設
A1 比我設定想generate幾多條飛
A2-F2 係第一張飛既號碼
A3-F3 係第二張飛既號碼
如始類推

我唔識諗probability果度
同埋點樣check有冇重覆number. if,then,else 果類logic我好弱

回答 (4)

2011-08-22 7:52 am
✔ 最佳答案
Sub XXX()

Dim i%, rng As Range
[h1:n7] = "=RAND()"

For i = 1 To [A1]
Set rng = Cells(i + 1, 1).Resize(1, 6)
rng.Value = Application.Rank([h1:m1], [h1:n7])
rng.Sort key1:=Cells(i + 1, 1), Orientation:=xlLeftToRight
Next

End Sub


2011-08-22 00:03:38 補充:
~~~~~~~~~~~~

公式解法:

連選h1:n100
輸入公式 =RAND()
兩鍵連按:Ctrl-Enter

A1
=SMALL(RANK($H1:$M1,$H1:$N7),COLUMN(A1))
三鍵連按: Ctrl - Shift - Enter
右拉至F1
下拉

你可以下拉出九十多條票
2011-08-22 8:31 am
Randomize
A = Rnd()
2011-08-21 8:20 pm
參考: MySelf


收錄日期: 2021-04-20 01:00:31
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20110820000051KK01030

檢視 Wayback Machine 備份