+ Reply to Thread
Results 1 to 9 of 9

Cull rows based on searching for text in a column.

  1. #1
    Registered User
    Join Date
    07-06-2012
    Location
    Georgetown, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    5

    Exclamation Cull rows based on searching for text in a column.

    I have a large spreadsheet with many, may worksheets in it. I've been asked to find a way to search for a particular text item in one column, and then, once it's found, to copy the row to a brand new worksheet. So...in other words...if in column B, we find the word "WHITE", the rest of the row information in that row is copied to a brand new spreadsheet.

    Someone is trying to cull any records that contain a specific word to a new worksheet.

    We're using Excel 2010.

    I'm not an Excel expert, so I'm hoping someone may be able to help!

    Many thanks!

    Pat

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Cull rows based on searching for text in a column.

    Pat,

    Welcome to the forum!
    Give this macro a try:
    Please Login or Register  to view this content.


    How to use a macro:
    1. Make a copy of the workbook the macro will be run on
      • Always run new code on a workbook copy, just in case the code doesn't run smoothly
      • This is especially true of any code that deletes anything
    2. In the copied workbook, press ALT+F11 to open the Visual Basic Editor
    3. Insert | Module
    4. Copy the provided code and paste into the module
    5. Close the Visual Basic Editor
    6. In Excel, press ALT+F8 to bring up the list of available macros to run
    7. Double-click the desired macro (I named this one tgr)
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Cull rows based on searching for text in a column.

    Sorry tigeravatar I did not see your post - this may be another option. Sorry about that tigeravatar as I don't like over posting other contributors.

    the rest of the row information in that row is copied to a brand new spreadsheet.
    So you do not copy the entire row just everything from column C to end of the row - are the rows fixed width or do they vary. It is not hard to iterate through the entire workbook and check every sheet for a keyword and then copy the data across to a new worksheet. If you could just upload a sample workbook just showing how the data is set out, where the value/word will occur (which column) and what data is copied across to new worksheet - like a before and after - only need a few entries just so can see how the data is set out. Depending on your VBA skills you could modify something like the following (this searches Column B). I have not tested this code - I have just modified it from previous project. As I say a sample worksheet would help
    Please Login or Register  to view this content.
    Depending on your VBA skill level you could modify this. Add this to a module and change the values I have marked
    Last edited by smuzoen; 07-06-2012 at 01:07 PM.
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

  4. #4
    Registered User
    Join Date
    07-06-2012
    Location
    Georgetown, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    5

    Exclamation Re: Cull rows based on searching for text in a column.

    Thank you so much tgravatar!!!

    One little hitch, tho!

    The macro works beautifully, except it deletes the searched text from the original rows.

    So...if I'm searching for White, every where that White exists in the spreadsheet is now blank!

    Would you be able to tell me how to modify the macro?

    I am sorry to come begging again....

    Cheers,

    Pat

  5. #5
    Registered User
    Join Date
    07-06-2012
    Location
    Georgetown, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Cull rows based on searching for text in a column.

    Oops...I just saw the post by smuzoen!

    I'll delete the last line in the macro!

    So sorry...I guess I should read more!

    Pat

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Cull rows based on searching for text in a column.

    pthielan,

    I deleted the original contents because you used the word "Cull" which meant to me that you wanted to move the items to a new sheet and delete them from their original locations. If that is not the case, you just need to delete this line in the macro so that the items do not get deleted from their original locations:
    Please Login or Register  to view this content.


    [EDIT]
    @smuzoen, no worries about posting here. The more solutions, the better I say
    Last edited by tigeravatar; 07-06-2012 at 03:11 PM.

  7. #7
    Registered User
    Join Date
    07-06-2012
    Location
    Georgetown, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Cull rows based on searching for text in a column.

    Hello all,

    I've just tried smuzoen's code and it didn't work at all, I'm sorry to say.

    So..unfortunately tigeravatar's code works the best, but still clears the cells of their original text. I wish I knew this stuff better...but unfortunatly I'm at the mercy of you guys!!

    Thanks,

    pat

  8. #8
    Registered User
    Join Date
    07-06-2012
    Location
    Georgetown, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Cull rows based on searching for text in a column.

    Just saw your post tigeravatar! Works beautifully. Sorry if I mislead you!!!

    Pat

  9. #9
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Cull rows based on searching for text in a column.

    Sorry - my code was not tested - glad tigeravatar's code worked. For what it is worth (now tested)
    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)

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