chatGPTで適当に自分用に貼り付け用

おもにエクセルのマクロ

以下は、修正後のプログラムです。このプログラムでは、カレンダーの日付をB2から行で、スタッフをA2から列で表示し、出勤のスタッフは日付の行に"○"を入れるように設定します。

```vba
Sub CreateShift()
Dim staff As Variant
Dim attendance As Variant
Dim numOfStaff As Integer
Dim shiftCount As Integer
Dim daysPerMonth As Integer
Dim startDate As Date
Dim endDate As Date
Dim currentRow As Integer
Dim currentColumn As Integer
Dim i As Integer
Dim j As Integer

'スタッフの名前
staff = Array("スタッフ1", "スタッフ2", "スタッフ3", "スタッフ4", "スタッフ5", "スタッフ6")

'土日祝の出勤回数
attendance = Array(0, 0, 0, 0, 0, 0)

numOfStaff = UBound(staff) + 1
daysPerMonth = 31 '対象の月の日数を設定
shiftCount = daysPerMonth \\\/ 2 '1日2人出勤なのでシフト数は出勤日数の半分

startDate = DateSerial(2023, 12, 1) '対象の月の開始日を設定
endDate = DateSerial(2023, 12, daysPerMonth) '対象の月の終了日を設定

currentRow = 2 'カレンダーの日付行の開始行
currentColumn = 2 'スタッフ行の開始列

'カレンダーの日付を設定
For i = 0 To daysPerMonth - 1
Cells(currentRow, currentColumn + i).Value = startDate + i
Next i

'スタッフを設定し、出勤日に"○"を入れる
For i = 0 To daysPerMonth - 1
For j = 0 To shiftCount - 1
Dim randomIndex As Integer
Dim selectedStaff As String

Do
randomIndex = Int((numOfStaff - 1 + 1) * Rnd + 1)
selectedStaff = staff(randomIndex - 1)
Loop Until attendance(randomIndex - 1) < shiftCount

attendance(randomIndex - 1) = attendance(randomIndex - 1) + 1
Cells(currentRow + j, currentColumn + i).Value = selectedStaff
Next j
Next i
End Sub
```

このプログラムを実行すると、対象の月のカレンダーを作成し、スタッフをランダムにシフトに配置します。出勤するスタッフは該当の日に"○"を入れます。

なお、この例では2023年12月の日数を31日に設定していますが、必要に応じて変更する必要があります。また、カレンダーの開始日は`startDate`で指定し、その月の日数は`daysPerMonth`で指定しています。同様に、スタッフ行の開始列は`currentColumn`で指定していますので、必要に応じて変更してください。