|
- Sub 随机菜单()
- Dim r%, i%
- Dim arr(1 To 3), brr
- Randomize Timer
- brr = [{1,2,1}]
- With Worksheets("菜谱")
- For j = 1 To 3
- r = .Cells(.Rows.Count, j).End(xlUp).Row
- arr(j) = .Cells(2, j).Resize(r - 1, 1)
- Next
- End With
- With Worksheets("今日菜单")
- For k = 1 To UBound(brr)
- For i = 1 To Application.Min(brr(k), UBound(arr(k)) - 1)
- m = Int((UBound(arr(k)) - i) * Rnd()) + 1 + i
- temp = arr(k)(i, 1)
- arr(k)(i, 1) = arr(k)(m, 1)
- arr(k)(m, 1) = temp
- Next
- For i = 1 To Application.Min(brr(k), UBound(arr(k)) - 1)
- .Cells(i + 1, k) = arr(k)(i, 1)
- Next
- Next
- End With
- End Sub
复制代码 |
|