1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Excel VBA Macro to delete rows/columns with criteria

Discussion in 'Business Applications' started by anamque, Jul 9, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. anamque

    anamque Thread Starter

    Joined:
    May 25, 2010
    Messages:
    29
    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?
     
  2. turbodante

    turbodante

    Joined:
    Dec 19, 2008
    Messages:
    744
    To delete column c, use:

    Code:
    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:

    Code:
    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




     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/934475