Deleting Rows with Reverse Loop - VB

前端 未结 1 1214
小蘑菇
小蘑菇 2021-01-25 03:53

I have a dataset that contains a bunch of information on customers. I want this information moved into another worksheet when Yes is entered into the Cell in row

相关标签:
1条回答
  • 2021-01-25 04:11

    It is generally more efficient to delete all your rows at once.

    Set c = Nothing 'reset your range
    For i = 1 To 500 'or 500 To 1 Step -1 - doesn't make a difference
        If Source.Range("K" & i) = "yes" Then
            If c Is Nothing Then
                Set c = .Cells(i, 1).EntireRow 'if the range is empty then set it to the required row
            Else
                Set c = Union(c, .Cells(i, 1)).EntireRow 'otherwise add this row
            End If
        End If
    Next
    If Not c Is Nothing Then c.Delete xlUp 'if the range is not empty then delete all the rows
    

    (I should add that my use of Cells(x,y).EntireRow is purely a personal preference. I always use that format as I find it easier to debug.)

    0 讨论(0)
提交回复
热议问题