在Sheet1
我有一个单元格A3
(包含例如52
):
Dim wbThis As Workbook
Dim wsThis As Worksheet
Dim wsTarget As Worksheet
Dim tmp As Integer
Set wbThis = ActiveWorkbook
Set wsThis = wbThis.Sheets(1)
Set wsTarget = wbThis.Sheets(2)
For i=1 To 100
wsThis.Activate
tmp = wsThis.Cells(3, i).Value
For j=3 To 100
wsTarget.Activate
If Cells(j,1).Value = tmp Then
Cells(j,1).EntireRow.Delete
End If
Next j
Next i
End Sub
但仍有问题:tmp = wsThis.Cells(3, i).Value----> Error written : Incompatible Type
我尝试了另一个代码,但它不起作用,该行未被删除。
Sub delete_ligne()
Dim rng as Range
Dim WB as Workbook
Dim i As Integer
Application.ScreenUpdating = False
Set WB = 'define your workbook here
Set rng = WB.Sheet(2).Range("B:B").Find (What:=WB.Sheet(1).Range("A3"), _
LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
While not Rng is Nothing
rng.Rows(1).EntireRow.Delete
Set rng = WB.Sheet(2).Range("B:B").Find (What:=WB.Sheet(1).Range("A3"), _
LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
Wend
Application.ScreenUpdating = True
End Sub