代码如下。
打开你的Excel文件,按“Alt+F11”打开VBA编辑窗口,然后在左侧对应的Sheet上双击,右侧空白处粘贴下面的代码。关闭VBA窗口。然后按“Alt+F8”打开宏窗口,选择刚插入的宏,点击“执行”。
Sub xh()Dim rg As RangeDim i, r, n As Longr = Cells(Rows.Count, 2).End(xlUp).RowFor Each rg In Range("B2:B" & r) If rg.Row = 2 Then n = 0 Else If rg.Value = rg.Offset(-1, 0).Value Then n = n + 1 Else n = 0 End If rg.Offset(0, -1).Value = nNextFor i = r To 2 Step -1 If Cells(i, 1) = 0 Then If Cells(i + 1, 1) <> 1 Then Rows(i).Delete Else If Cells(i + 1, 1).Value = 0 Then Rows(i + 1).Insert: Cells(i + 1, 1).Value = "End" End IfNextEnd Sub


- 相关评论
- 我要评论
-