我怎样才能停止macros自行取消和隐藏行

我正在使用下面的代码来sorting电子表格与各种小计。 6个电子表格中有5个按预期工作。 在第六个电子表格中,我遇到了一个问题,Excel从子组中取消了一行。 在下面的例子中,行435从组的其余部分被删除,并且行436的高度降低到0.我已经查看了行435和436中的每个单元格,并且每个单元格与组中的其他行匹配。 在与手动录制sortingmacros的用户交谈之后,他们告诉我,他们有时也会碰到他们的电子表格。 这个macros适用于它必须要sorting的前27个组。 我有一个问题的子组有95行,其他组有更多的行没有问题。

有没有人遇到过这个问题,有人想出了如何处理它?

我使用的代码如下。

Sub mcrFindSortGroup() Dim strFirstRow As String Dim strLastRow As String Dim LastCol As Integer Dim c As Range Dim strColumn As String Application.DisplayAlerts = False Application.EnableCancelKey = xlDisabled Sheets("DCL Descriptions").Select Range("H2:H2").Select strColumn = ActiveCell strColumn = strColumn - 1 Sheets("Sku Selling").Select Columns("C:C").Select For Each c In Range("DCL") If c = "" Then GoTo DoneMsg Cells(ActiveCell.Row, 1).Select Range("C1:C15000").Activate Selection.Find(What:=c, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate strFirstRow = ActiveCell.Row Cells(ActiveCell.Row, 2).Select If Cells(ActiveCell.Row + 1, 2) <> Cells(ActiveCell.Row, 2) Then strLastRow = ActiveCell.Row GoTo SkipSort End If Range(Selection, Selection.End(xlDown)).Select strLastRow = ActiveCell.End(xlDown).Select strLastRow = ActiveCell.Row RowCount = (strLastRow - strFirstRow) + 1 Rows(strFirstRow & ":" & strLastRow).Select ActiveWorkbook.Worksheets("Sku Selling").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Sku Selling").Sort.SortFields.Add Key:=ActiveCell _ .Offset(0, strColumn).Range("A" & 1 & ":A" & RowCount) _ , SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("Sku Selling").Sort .SetRange ActiveCell.Range("A" & 1 & ":ZZ" & RowCount) .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With SkipSort: ' the group has only 1 sku and does not need to be sorted Next DoneMsg: MsgBox "Sorting Completed!", vbInformation, "Done" Application.DisplayAlerts = True Application.EnableCancelKey = xlErrorHandler End Sub 

这些是在屏幕截图之前和之后

之前: 在这里输入图像说明

后: 在这里输入图像说明