ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

½Ð°ÝEXCEL VBA

½Ð°ÝEXCEL VBA

½Ð°Ý¤@¤U¦p¦ó§Q¥ÎVBA«ü©w¤@­Ó½d³ò¶]¥X¶Ã¼Æªí¡AÁÂÁ¡C

¦p¤U¤Þ¥Î«e½ú§@«~

Sub ¶Ã¼Æ¤£­«½Æ()

Const rnd_start = 11 '¶Ã¼Æ±Ò©l­È
Const rnd_end = 20 '¶Ã¼Æµ²§ô­È
Const cell_start = 1 '­n²£¥Í¶Ã¼ÆªºÀx¦s®æ±Ò©l¦C
Const cell_end = 5 '­n²£¥Í¶Ã¼ÆªºÀx¦s®æµ²§ô¦C
Const Mycol = "A" '­n²£¥Í¶Ã¼ÆªºÀx¦s®æÄæ

Dim Buf_rnd As Long '¥Î¨Ó¼È®É¦s©ñ¶Ã¼Æ­È¡Aµ¥¤ñ¹ï¨S¦³­«½Æ«á¤~¦s¤JÀx¦s®æ
Dim i As Long
Dim j As Long

If rnd_end - rnd_start < cell_end - cell_start Then
MsgBox "²£¥Í¤£­«½Æªº¶Ã¼Æ°Ï¶¡¤£¥i¥H¤ñ­n²£¥Í¶Ã¼ÆªºÀx¦s®æªº¼Æ­ÈÁÙ­n¤Ö¡C"
Exit Sub
End If

'²£¥Í¶Ã¼Æ
For i = cell_start To cell_end
1 Buf_rnd = Int(Rnd() * (rnd_end - rnd_start + 1)) + rnd_start
'¦pªG¤£¬O²Ä1­ÓÀx¦s®æ´N­n©¹«e¤ñ¹ï¡C
If i > cell_start Then
For j = cell_start To i - 1
'¦pªG­«½Æ¤F´N¸õ¨ì 1 ­«·s²£¥Í¶Ã¼Æ¡C
If Buf_rnd = Range(Mycol & j).Value Then GoTo 1
Next j
End If
Range(Mycol & i).Value = Buf_rnd
Next i

End Sub
ù

TOP

        ÀR«ä¦Û¦b : ¦³´¼¼z¤~¯à¤À¿ëµ½´c¨¸¥¿¡F¦³Á¾µê¤~¯à«Ø¥ß¬üº¡¤H¥Í¡C
ªð¦^¦Cªí ¤W¤@¥DÃD