Search code examples
excelvbadelete-row

Totally remove row in Excel VBA


In my VBA macro, I need to totally remove some rows. The following code deletes all the values in the rows - leaving blank, empty rows - but does not actually delete the rows. How do I do that?

    For i = UBound(DataArray) To LBound(DataArray) + 1 Step -1
       Rows(DataArray(i, 1)).Delete
    Next i

TIA.

Trying to remove empty rows shown here


Solution

  • This seems to be deleting rows (below screenshot of before & after running the code);

    Sub code()
    
    Dim DataArray(6 To 10) As String
    For i = UBound(DataArray) To LBound(DataArray) + 1 Step -1
        Rows(i).Delete
    Next i
        
    End Sub
    

    Before running the above code;

    enter image description here

    After Running the code; ID number 6,7,8,9 are deleted...

    enter image description here