+ Reply to Thread
Results 1 to 4 of 4

Macro to Compare to Cells and Delete Row

  1. #1
    Forum Contributor
    Join Date
    07-24-2008
    Location
    San Antonio, Texas
    Posts
    118

    Macro to Compare to Cells and Delete Row

    I am trying to write some code that will compare two cells on a row and if they match then it will delete the row.

    Column A-has the number 1, 2, 3, 4, or 5 entered
    Column B-has either a date or is blank

    I need the macro to look at Column A and Column B and for example if the cell A2 has a 3, 4, or 5 and B2 is blank the macro will delete that row.

    The spreadsheet will vary on how many rows it contains. It can contain up to 5,000 rows and the macro would need to go through all the rows.

    Any help would be greatly appreciated. Thanks

  2. #2
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845
    Hi,

    I put 2 codes here for you to look at.
    the first code "test" looks at column "B" and if its not a date t will delete the row.
    The "test1" code is basically the same except it checks column "B" for blanks if blank then it will delete that row.

    The codes will start from the last row of column "A".



    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  3. #3
    Forum Contributor
    Join Date
    07-24-2008
    Location
    San Antonio, Texas
    Posts
    118
    Well I figured out why the previous to code examples were not working I have included a correction as to what I am needing.

    I am trying to write some code that will compare two cells on a row and if they match then it will delete the row.

    Column A-has the number 1, 2, 3, 4, or 5 entered
    Column B-has either a date or is blank

    I need the macro to look at Column A and Column B and for example if the cell A2 has a 3, 4, or 5 and B2 has a date the macro will delete that row.
    The spreadsheet will vary on how many rows it contains. It can contain up to 5,000 rows and the macro would need to go through all the rows.
    Any help would be greatly appreciated. Thanks

  4. #4
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845
    Hi,

    You want it to delete if blank or has a date.
    Then try

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1