回答編集履歴
2
コード微修正
test
CHANGED
@@ -138,7 +138,7 @@
|
|
138
138
|
|
139
139
|
' 戻り値 : なし '
|
140
140
|
|
141
|
-
' 使用例 : AryShuffle(MyArray) '
|
141
|
+
' 使用例 : Call AryShuffle(MyArray) '
|
142
142
|
|
143
143
|
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
144
144
|
|
1
コード追記
test
CHANGED
@@ -61,3 +61,111 @@
|
|
61
61
|
|
62
62
|
|
63
63
|
これだと作業シートを使わずできます。
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
この方法でコードを書いてみたのでご参考に。
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
```vba
|
72
|
+
|
73
|
+
Public Sub SetSeatingChart()
|
74
|
+
|
75
|
+
Dim SeatList As String 'セル番地をカンマ区切りで格納
|
76
|
+
|
77
|
+
SeatList = _
|
78
|
+
|
79
|
+
"N11,N15,N19,N23,N31,N35,N39,N43," & _
|
80
|
+
|
81
|
+
"R11,R15,R19,R23,R31,R35,R39,R43," & _
|
82
|
+
|
83
|
+
"W11,W15,W19,W23,W31,W35,W39,W43," & _
|
84
|
+
|
85
|
+
"AF11,AF15,AF19,AF23,AF31,AF35,AF39,AF43," & _
|
86
|
+
|
87
|
+
"AF11,AF15,AF19,AF23,AF31,AF35,AF39,AG43," & _
|
88
|
+
|
89
|
+
"AP19,AP23,AP31,AP35," & _
|
90
|
+
|
91
|
+
"AI19,AI23,AI31,AI35," & _
|
92
|
+
|
93
|
+
"AT11,AT15,AT19,AT23,AT31,AT35,AT39,AT43," & _
|
94
|
+
|
95
|
+
"AY11,AY15,AY19,AY23,AY31,AY35,AY39,AY43," & _
|
96
|
+
|
97
|
+
"BC11,BC15,BC19,BC23,BC31,BC35,BC39,BC43," & _
|
98
|
+
|
99
|
+
"BH11,BH15,BH19,BH23,BH31,BH35,BH39,BH43," & _
|
100
|
+
|
101
|
+
"BL11,BL15,BL19,BL23,BL31,BL35,BL39,BL43"
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
Dim ArySeat
|
106
|
+
|
107
|
+
ArySeat = Split(SeatList, ",") '配列に変換
|
108
|
+
|
109
|
+
Call AryShuffle(ArySeat) '配列をシャッフル
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
Dim AryName
|
114
|
+
|
115
|
+
AryName = Range("A1:A88").Value 'A1:A87セルに名前が記入されているとする
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
Dim i As Long
|
120
|
+
|
121
|
+
For i = LBound(ArySeat) To UBound(ArySeat)
|
122
|
+
|
123
|
+
Range(ArySeat(i)).Value = AryName(i + 1, 1)
|
124
|
+
|
125
|
+
Next
|
126
|
+
|
127
|
+
End Sub
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
132
|
+
|
133
|
+
' 引数 : バリアント配列、動的配列、配列 '
|
134
|
+
|
135
|
+
' 宣言例 Dim MyArray As Variant '
|
136
|
+
|
137
|
+
' 目的 : 配列をランダムに並べ替える '
|
138
|
+
|
139
|
+
' 戻り値 : なし '
|
140
|
+
|
141
|
+
' 使用例 : AryShuffle(MyArray) '
|
142
|
+
|
143
|
+
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
144
|
+
|
145
|
+
Public Sub AryShuffle(ByRef MyAry)
|
146
|
+
|
147
|
+
Dim i As Integer, buf, UB As Integer, P As Integer
|
148
|
+
|
149
|
+
If IsNull(MyAry) Then Exit Sub
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
Randomize
|
154
|
+
|
155
|
+
UB = UBound(MyAry)
|
156
|
+
|
157
|
+
For i = UB To 1 Step -1
|
158
|
+
|
159
|
+
P = Int((i + 1) * Rnd)
|
160
|
+
|
161
|
+
buf = MyAry(P)
|
162
|
+
|
163
|
+
MyAry(P) = MyAry(i)
|
164
|
+
|
165
|
+
MyAry(i) = buf
|
166
|
+
|
167
|
+
Next
|
168
|
+
|
169
|
+
End Sub
|
170
|
+
|
171
|
+
```
|