+ Reply to Thread
Results 1 to 5 of 5

Code to delete rows that do not contain certain text in a cell

  1. #1
    Registered User
    Join Date
    06-12-2012
    Location
    Chesterfield
    MS-Off Ver
    Excel 2010
    Posts
    3

    Code to delete rows that do not contain certain text in a cell

    Good morning - I am new to macros and would like some advice on a macro to help me delete rows in a worksheet that don't contain certain names.

    The example is that column F in my worksheet has a list of people's names and I need to delete all the names apart from one. So, for example, if the name was "M MOUSE", how can I delete all the rows in the sheet starting on row 6 that don't contain "M MOUSE"?

    Any help is much appreciated.

    Many thanks in advance.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Code to delete rows that do not contain certain text in a cell

    How is that one name decided? Will you need a popup box to ask the user to specify the name? Or should the macro take it from a particular cell?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    06-12-2012
    Location
    Chesterfield
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Code to delete rows that do not contain certain text in a cell

    Hi there

    A pop up box would be ideal but if there is code available for both options, that would be very handy indeed!

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Code to delete rows that do not contain certain text in a cell

    This is the code for the popup box.
    Please Login or Register  to view this content.
    This is the code if the name is provided in a cell -
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button.

  5. #5
    Registered User
    Join Date
    06-12-2012
    Location
    Chesterfield
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Code to delete rows that do not contain certain text in a cell

    Many thanks for your quick response on this - I'll have a play with Excel this afternoon.

+ 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