このテーブルを 1 時間あたりのトン数で並べ替えていますが、これまでのコードでヘッダーが削除され (下の 2 行目は上に移動しただけです)、これが起こらないようにする方法がわかりません。また、リストがソートされたら、左端の列のセルをマージして、各行の範囲を示すのではなく、異なる数値範囲をグループ化します。範囲を 6 ~ 8、10 ~ 15、16 ~ 21、24 ~ 28 にする必要があります。前もって感謝します。
Sub SystemSize()
Dim LastRow As Long
LastRow = Range("I" & Rows.Count).End(xlUp).Row
Dim I As Long, Groups As Long
Range("A2:I" & LastRow).Sort key1:=Range("I2"), order1:=xlAscending 'Sorts data
Groups = 1
Do While Groups < 8
I = 2
Select Case Groups
Case 1
For j = 2 To LastRow
If Cells(j, 9) >= 6 And Cells(j, 9) <= 8 Then
Cells(j, 1) = "6-8 MTPH" 'Cells(j, 1)
I = I + 1
End If
Next
Case 2
For j = 2 To LastRow
If Cells(j, 9) >= 10 And Cells(j, 9) <= 15 Then
Cells(j, 1) = "10-15 MTPH"
I = I + 1
End If
Next
Case 3
For j = 2 To LastRow
If Cells(j, 9) >= 16 And Cells(j, 9) <= 21 Then
Cells(j, 1) = "16-21 MTPH"
I = I + 1
End If
Next
Case 4
For j = 2 To LastRow
If Cells(j, 9) >= 24 And Cells(j, 9) <= 28 Then
Cells(j, 1) = "24-28 MTPH"
I = I + 1
End If
Next
Case 5
For j = 2 To LastRow
If Cells(j, 9) >= 30 And Cells(j, 9) <= 38 Then
Cells(j, 1) = "30-38 MTPH"
End If
Next
Case 6
For j = 2 To LastRow
If Cells(j, 9) >= 40 And Cells(j, 9) <= 48 Then
Cells(j, 1) = "40-48 MTPH"
I = I + 1
End If
Next
Case 7 'this added to pick up data that does not fall into a group, like 8 or 9
For j = 2 To LastRow
If Cells(j, 9) > 0 And Cells(j, 9) < 6 Or Cells(j, 9) > 48 Then
Cells(j, 1) = "No Group"
I = I + 1
End If
Next
End Select
Groups = Groups + 1
Loop
End Sub