# 根据一系列条件删除行（复数）

##### 问题描述投票：1回答：2

``````Sub test()

Dim x As Long
Dim lastrow As Long

lastrow = Sheets("LRP").ListObjects("Data_LRP").Range.Rows.Count

Worksheets("LRP").Activate
For x = lastrow To 1 Step -1
If Cells(x, 1).Value = "30ExGEPAc30Q4" Then
Rows(x).Delete
End If
Next x
End Sub
``````
excel vba range
##### 2个回答
0

``````Sub test()

Dim x As Long
Dim lastrow As Long

'lastrow = Sheets("LRP").ListObjects("Data_LRP").Range.Rows.Count
x = 1
lastrow = 21

'Worksheets("LRP").Activate
Do While x <= lastrow
'    For x = lastrow To 1 Step -1
If Cells(x, 1).Value = "30ExGEPAc30Q4" Then
Rows(x).Delete
lastrow = lastrow - 1
Else
x = x + 1
End If
'    Next x

Loop
End Sub
``````

0

``````Sub Cull()

Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim sht1row As Long
Dim sht2row As Long
Dim sht2total As Long
Dim DupID As String

Set sht1 = Worksheets("Data Form")
Set sht2 = Worksheets("LRP")
sht2.Activate
sht2total = Worksheets("LRP").ListObjects("Data_LRP").Range.Rows.Count
sht1row = 33

Do While sht1.Cells(sht1row, 2).Value <> ""

DupID = sht1.Cells(sht1row, 2).Value

For sht2row = 2 To sht2total

If DupID = Cells(sht2row, 1).Value Then

Rows(sht2row).Delete
sht2row = sht2row - 1
Exit For

End If

Next

sht1row = sht1row + 1

Loop

End Sub
``````