# Excel VBA Macro to delete rows/columns with criteria



## anamque (May 25, 2010)

Hello - I found a previous post on this site that solves (I think) 90% of what I need to accomplish. I have a large spreadsheet that I need to: 

· Delete column C
· Delete all rows without account numbers (Acct numbers will always be in column A)
· Delete all rows that have dates in column F other than "00/00/0000".

The code I found on this site is :

Simple vba code:
lastrow = Range( "A65536").end(xlup).row
For y = LastRow To 2 Step -1
If Cells(y, x).Value = "" Then Cells(y, x).Delete shift:=xlUp
Next y
Set the range to the the column desired, in this case "A"
Lastrow checks the last row and starts from the end up.
Removes all empty rows entirely up to row 2 because row 1 generally is the header
Happy coding 

Can anyone help me?


----------



## turbodante (Dec 19, 2008)

To delete column c, use:



```
Columns("E").EntireColumn.Delete
```


Delete all rows without account numbers (Acct numbers will always be in column A)
and
If Cells(y, "A").Value = "" Then Cells(y, "A").Delete shift:=xlUp

Use:



```
lastrow = cells(rows.count,1).end(xlup).row
For y = LastRow To 2 Step -1
If  Cells(y, "A").Value = "" Then Rows(y).EntireRow.Delete 
If  Cells(y, "F").Value =  00/00/0000 Then Rows(y).EntireRow.Delete ' Delete all rows that have dates in column F other  than 00/00/0000.
Next y
```


----------

