简体   繁体   中英

Delete Rows in excel using VBA

I want to run a code that will go down all of column D (D:D) in my sheet named PxV and if they find a blank cell it will completely delete that corresponding row. Another caveat is idk if my cells are truly blank? There is a formula running through all the cells and if it is false returns "". Idk if this would be recognized as blank by VBA so if you would have to delete cells that have "" even though they're blank. It would also be nice to run continuously so when new data is populates it runs but I am not sure if that is possible . Thanks!!!

See if this works. You'll need to edit the code to match your sheet name and column.

Sub DelRow()
Dim ws As Worksheet
Dim SheetsToSearch, SrchStrg As String, r As Range
Set ws = Sheets("Sheet1")
SrchStrg = ""
SrchStrg2 = 0

Application.ScreenUpdating = False
    With ws.Range("A:A")
        Set r = .Find(what:=SrchStrg, After:=.Range("A1"))
        For Each r In ws.Range("A1:A1000")
            If r = SrchStrg Then
                r.EntireRow.Delete
            ElseIf r = SrchStrg2 Then
                r.EntireRow.Delete
            End If
        Next
    End With
Application.ScreenUpdating = True
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM