# 查看完整版本 : 求問 Excel 程式難題

Henry-Loi 2020-7-13 05:17 PM

## 求問 Excel 程式難題

A2=IF(A1=ROUND(RAND()*14,0)+1,ROUND(RAND()*14,0)+1,)

A2=IF(A1<>ROUND(RAND()*14,0)+1,ROUND(RAND()*14,0)+1,)

[[i] 本帖最後由 Henry-Loi 於 2020-7-13 05:23 PM 編輯 [/i]]

alee001 2020-7-13 09:25 PM

YjgfkHJj 2020-7-13 10:27 PM

Syntax for IF:

IF( condition, value_if_true, [value_if_false] )

A2=IF(A1=ROUND(RAND()*14,0)+1,ROUND(RAND()*14,0)+1,)
both blocks are the same ! (ROUND(RAND()*14,0)+1)

so if A1 equals to [ROUND(RAND()*14,0)+1]

then u set A2 to [ROUND(RAND()*14,0)+1]

then of coz A2 is equal to A1 la!

:P

A1點解唔用randbetween?

111x111=12321 2020-7-14 12:44 PM

[quote]原帖由 [i]煙民母親生賤種[/i] 於 2020-7-13 11:40 PM 發表 [url=https://computer.discuss.com.hk/redirect.php?goto=findpost&pid=521603135&ptid=29213354][img]https://computer.discuss.com.hk/images/common/back.gif[/img][/url]

[quote]原帖由 [i]凡間忠盒子[/i] 於 2020-7-14 10:50 AM 發表 [url=https://computer.discuss.com.hk/redirect.php?goto=findpost&pid=521619261&ptid=29213354][img]https://computer.discuss.com.hk/images/common/back.gif[/img][/url]
A1點解唔用randbetween? [/quote]

patpat904 2020-7-17 10:29 PM

Dim var(5) As Integer
Dim tmp As Integer

For i = 1 To 5

tmp = Int((15 - 1 + 1) * Rnd + 1)
For j = 1 To i
If var(j) = tmp Then
tmp = Int((15 - 1 + 1) * Rnd + 1)
Else
var(i) = tmp
End If
Next

ThisWorkbook.ActiveSheet.Cells(i, 1) = var(i)

Next