我的宏有问题.它会删除满足某些条件的行.但是,当连续几行完全满足这些标准时,就会发生错误.删除行时,其他行向上移动,因此如果行(2:2)和行(3:3)满足条件,则删除行(2:2)并向上移动行(3:3) ,因此它变为row(2:2),For循环进入另一行(第三行).结果,以前是行(3:3)并且现在是行(2:2)的行被省略并且不被删除.
为了处理这个话题,我认为它足以逆转For循环,因此它不会从上到下而是从下到上.Te resulat会对某些行进行双重检查,但不会省略任何行.
问题是我不知道如何揭示For循环.我试图将'For x = startrow to endrow'更改为'For x = endrow to startrow',但它没有帮助.
这是代码:
Sub Repurchase_upload()
Dim Worksheet As Worksheets
startrow = Worksheets("GUTS").Cells(10, 1)
endrow = Worksheets("GUTS").Cells(11, 1)
For x = startrow To endrow 'I have tried to change this line into: 'For x = endrow To startrow', but it didn' help
If Cells(x, "A").Value <> "AA" And Cells(x, "A").Value <> "AB" And Cells(x, "A").Value <> "AC" And Cells(x, "A").Value <> "AD" And Cells(x, "A").Value <> "AE" And …Run Code Online (Sandbox Code Playgroud) 我试图删除使用VBA在B列中找到值"X"的每一行.但是,我有三个问题:
任何帮助将不胜感激.
Sub RemoveRows()
Dim strLookFor As String
Dim strRow As String
Worksheets("Sheet1").Range("B2").Activate
strLookFor = "X"
strRow = Range("B2").Address
Do Until ActiveCell.Value = ""
MsgBox (ActiveCell.Value)
If ActiveCell.Value = strLookFor Then
Rows.Delete (strRow)
End If
strRow = Cells.Find(what:=strLookFor).Address
Loop
MsgBox ("Deleted all rows with value " & strLookFor)
End Sub
Run Code Online (Sandbox Code Playgroud)
