Sub 行_グループ化()
Dim r_end As Long Dim c_end As Long Dim w_active As Range Dim i As Integer Dim i1 As Integer Dim s As Worksheet Set s = ActiveSheet Set w_active = ActiveCell With s.UsedRange r_end = .Row + .Rows.Count - 1 c_end = .Column + .Columns.Count - 1 End With s.Cells.Select On Error Resume Next Selection.Rows.Ungroup Selection.Rows.Ungroup Selection.Rows.Ungroup On Error GoTo 0 For i = 3 To r_end If s.Cells(i, 1).Value <> "" And s.Cells(i, 1).Value = 2 And s.Cells(i + 1, 1).Value > 2 Then For i1 = i + 1 To r_end + 1 If s.Cells(i1, 1).Value = "" Or s.Cells(i1, 1).Value <= 2 Then Exit For End If Next i1 s.Range(s.Rows(i + 1), s.Rows(i1 - 1)).Select Selection.Rows.Group End If Next i w_active.Select End Sub