使用VBA excel在组内创build组

所以在我的文件中,我有一个看起来像这样的列:

4 4 4 5 5 5 4 3... 

连续4s需要组合在一起,然后连续5s在一起,5s是一个4的子组。我写了一个代码,为5s工作,但一旦我执行它为4s它不创build新的子组,但包括4s在已经存在的组中(或类似的):

 Sub Button1_Click() Dim c As Integer Dim i As Integer Dim alpha As Integer Dim lim As Long lim = 15000 alpha = 4 Do while alpha <> 1 For i = 11 To lim If Cells(i, 2) = alpha Then c = c + 1 End If If Cells(i, 2) <> alpha And c <> 0 Then Range(Cells(i - 1, 2), Cells(i - c, 2)).Select Selection.Rows.Group c = 0 End If Next alpha = alpha - 1 Loop End Sub