クラス別名簿を作成する | 複数の学年の名簿を作成する |
関数で名簿を作成する | VBAで名簿を作成する |
Sub meibo() Dim gakunen Dim class1(1 To 50, 1 To 6) Dim class2(1 To 50, 1 To 6) Dim class3(1 To 50, 1 To 6) Dim cn1 As Integer, cn2 As Integer, cn3 As Integer Dim i As Long, j As Long gakunen = Worksheets("名簿").Range("A2:F90").Value For i = 1 To UBound(gakunen) Select Case gakunen(i, 4) Case 1 cn1 = cn1 + 1 For j = 1 To 6 class1(cn1, j) = gakunen(i, j) Next j Case 2 cn2 = cn2 + 1 For j = 1 To 6 class2(cn2, j) = gakunen(i, j) Next j Case 3 cn3 = cn3 + 1 For j = 1 To 6 class3(cn3, j) = gakunen(i, j) Next j End Select Next i Worksheets("1組").Range("A2").Resize(UBound(class1), 6).Value = class1 Worksheets("2組").Range("A2").Resize(UBound(class2), 6).Value = class2 Worksheets("3組").Range("A2").Resize(UBound(class3), 6).Value = class3 End Sub |