LoginSignup
1
1

More than 3 years have passed since last update.

シャッフルするExcelマクロ

Last updated at Posted at 2019-07-31

これは

1~Nの整数をシャッフルして配列として返す関数。

コード

Function Shuffle(n As Long)
    With New Dictionary
        Do While .Count < n
            .Item(WorksheetFunction.RandBetween(1, n)) = 0
            DoEvents
        Loop
        Shuffle = .Keys
    End With
End Function

テスト

Sub Test_Shuffle()
    Dim arr
    arr = Shuffle(13)
    Debug.Print Join(arr)
End Sub

結果

9 12 8 7 5 10 6 1 11 4 2 3 13
1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1