|
|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub DeleteRows()
Dim i As Long, j As Long, c1 As Long, c2 As Long, m1 As Long, m2 As Long
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
Dim lastRow As Long: lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
Dim lastCol As Long: lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
For i = lastRow To 1 Step -1
c1 = 0: c2 = 0: m1 = 0: m2 = 0
For j = 1 To lastCol
Select Case ws.Cells(i, j).Value
Case 1: c1 = c1 + 1: c2 = 0: If c1 > m1 Then m1 = c1
Case 2: c2 = c2 + 1: c1 = 0: If c2 > m2 Then m2 = c2
Case Else: c1 = 0: c2 = 0
End Select
Next
If m1 > 2 Or m2 > 3 Then ws.Rows(i).Delete
Next
End Sub |
|