+ Reply to Thread
Results 1 to 10 of 10

VBA Does not contain

  1. #1
    Registered User
    Join Date
    06-16-2014
    Posts
    5

    Cool VBA Does not contain

    Dear All,

    I am an intern and I've been tasked with figuring out how to delete all rows in a spreadsheet which are not flagged as not important data. In VBA i want to write a code where excel can delete those in important data for me. The cells which are containing n or c must be deleted. How can i do that?

    Thank you so much!

  2. #2
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: VBA Does not contain

    Is the n or c always in the same column of the row? Could you attach a sample workbook with a before and after tab with non sensitive data?

  3. #3
    Registered User
    Join Date
    06-16-2014
    Posts
    5

    Re: VBA Does not contain

    He! Je bent Nederlands

    No they are not. It is a number so the number starts with .../../00231 or ..../../N0231 or .../../C0231. I only need the numbers which are written like the first one. (see row F)example.xlsx

    I can make a sample, but i can not add the original document

  4. #4
    Registered User
    Join Date
    06-16-2014
    Posts
    5

    Re: VBA Does not contain

    Range(F1).Select
    Do Until Selection.Value = "xxx"
    If Selection.Value = "N" Then
    Selection.EntireRow.Delete
    Else
    Selection.Offset(1, 0).Select
    End If
    Loop

    I already wrote this, but i am not sure if it is ok.

  5. #5
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: VBA Does not contain

    Based on your example I think something like this should work
    Please Login or Register  to view this content.
    Make sure you use code tags when attaching code, it helps the forum look nicer

    This code looks at all columns in column F and finds the values to the right of the last "/" and checks if it is a number or not. If it is not a number (any letter present) it deletes the row.

    This does not take into account if there are values without "/" in them, in which this macro will error out. Error handling would be needed for that scenario.
    Last edited by Hawkeye16; 06-16-2014 at 04:32 AM.
    Despite the high cost of living, it remains very popular.

    Don't forget to mark threads SOLVED when you get an answer and rep all the geniouses that helped you today!

  6. #6
    Registered User
    Join Date
    06-16-2014
    Posts
    5

    Re: VBA Does not contain

    But it looks like you delete the letters from the 'name' now? Because the intention is the delete the entire row if the name contains a c or a n.

    In excel i did: sort, does not contain c and n, ok.
    These are the steps i want to have in VBA.

  7. #7
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: VBA Does not contain

    Mine deletes the entire row if there is a letter present, not just if there is a C or N. It can easily be modified to test just for a C or N.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-16-2014
    Posts
    5

    Re: VBA Does not contain

    Thank you so much

  9. #9
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: VBA Does not contain

    No problem, don't forget to mark the thread as solved and add reputation if you would like!

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Does not contain

    FWIW:

    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