我按每小时公吨对这张表进行排序,到目前为止我的代码删除了标题(第二行向下移动了),我不知道如何使这种情况不发生。此外,我想在列表排序后合并最左列中的单元格,以便将不同的数字范围分组,而不是在每一行中说明范围。我需要范围为 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