+ Reply to Thread
Results 1 to 6 of 6

How to delete all rows if any cells in the row contain certain values.

  1. #1
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    How to delete all rows if any cells in the row contain certain values.

    Hello,

    I'm having a bit of trouble finding the most elegant way to prune some data from a spreadsheet that contains some stock price data.

    Some of the data I have is incomplete and as a result, some of the rows contain the following string of data: "#N/A N/A"

    What I'd like to be able to do is get a macro that looks for the last row in the spreadsheet that contains this string and delete every row where that occurs but stops at row 3

    I was wondering if anyone knows if I might be able to do this. I have attached a copy of an example spreadsheet.

    Many Thanks in advance for your suggestions,

    Kindest Regards,
    twills
    Attached Files Attached Files
    Last edited by twills; 02-14-2010 at 03:31 PM. Reason: Non compliance with forum rules

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: An elegant way to delete all rows if any cells in the row contain certain values.

    Hi twills,
    First of all in your sample file you have you have #NA in rows after 11 too. If I understand your request correctly, macro should delete all rows from 3 to 472 (this is the last row with #NA)
    Why don't you use filter? Set the filter in row 2 and apply it for value #NA in column B.
    Please Login or Register  to view this content.
    will give you the last row with data that is visible.
    Then you can delete the range from row 3 to r

    Buran
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,202

    Re: An elegant way to delete all rows if any cells in the row contain certain values.

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: An elegant way to delete all rows if any cells in the row contain certain values.

    Buran,

    Thank you for the suggestion, but I improperly worded the problem.

    I don't want to use filtering as it can get messy in VBA. I have around 7000 of these sheets to do, so automation is a priority!

    Once again, thanks for the suggestion.

    twills

  5. #5
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: An elegant way to delete all rows if any cells in the row contain certain values.

    Apologies royUK,

    It has now been amended.

    Thanks
    twills.

  6. #6
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: How to delete all rows if any cells in the row contain certain values.

    I mean use filter with VBA, so no problem with "automation is priority". By the way if you want to delete only the rows where #NA is, then you can use SpecialCells method of Range objecy and use type xlCellTypeVisible. But if you think it could be messy - I don't have other idea.
    Wish you luck and will look after this thread if someone suggest other solution
    Last edited by buran; 02-14-2010 at 03:42 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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