如何删除特殊行 [英] How to delete a special row
问题描述
在sheet1中,我有一个单元格A3(52):
In sheet1 I have one cell A3 (52):
在表2中,我想删除表1的A3号码的行。这个数字只能是在第一列。
In the sheet 2, I want to delete the row where there is the number of A3 of the sheet 1. This number can only be in the first column.
这是我的代码,但它不起作用:
Here is my code, but it doesn't work:
Sub delete_ligne()
Dim i As Integer
Application.ScreenUpdating = False
For i = 1 To 6600
If (Cells(i,1) = ThisWorkbook.Sheets("Modification").Range("B7").Value)
Then
Cells(i, 1).EntireRow.Delete
i = i - 1
End If
Next
Application.ScreenUpdating = True
End Sub
任何解决方案?
推荐答案
仍然不知道不工作是什么意思,但这可能有帮助:
Still not sure what "It doesn't work" means, but this might help:
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
调整以定义 WB
, Sheet(2)
和 Sheet(1)
根据需要指向正确的位置。
Adjust to define WB
, Sheet(2)
, and Sheet(1)
as necessary to point to the correct locations.
.Find
将显着更快比循环6600行,并且不在乎它找到/删除行的顺序。
The .Find
will be substantially faster than looping 6600 rows and doesn't care what order it finds/deletes the rows.
如果有更多的单元格被检查,您可以添加一个外部循环A3
You can add an outer loop if there are more cells to be checked that "A3"
这篇关于如何删除特殊行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!