+ Reply to Thread
Results 1 to 9 of 9

Show row if contains text, hide all others

  1. #1
    Registered User
    Join Date
    03-30-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    18

    Show row if contains text, hide all others

    Hi everyone,

    I've scoured the interwebs for hours now and cannot for the life of me get my code to work.

    I have a sheet with a dropdown box in cell "J1" which is meant as a 'Show only rows containing this value'.

    Column Q, from row 3 downward has a pick box which lists the same values as the "J1" drop down box, but uses code to combine whats chosen with commas. An example of what is in a cell in column Q is "SeaHawk, BlackHawk, Squirrel, MRH", where cell J1 would be either "SeaHawk" or "MRH" or something completely different.

    I need to only show rows, with text in column Q containing the smae text as J1.

    Any Ideas?

    Thanks Again
    AusTempest

  2. #2
    Registered User
    Join Date
    03-30-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Show row if contains text, hide all others

    This is an example of the worksheet i'm working with.

    I've deleted ~300+ rows and edited out the text that is not required for this code.
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Show row if contains text, hide all others

    Hi Austempest,

    I cannot get the code behind the page to fire, my first trick (after not understanding the code itself ) is to slap in a break point on the first executable line of the code so I can at least try the old F8 step through trick... cannot get it to break so I am guessing it is probably something to do with the worksheet change process (which is sadly a touch past where I can be really helpful )

    and by the way, welcome to to forums, someone will be able to help even if it isn't me just now

    Jmac

  4. #4
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: Show row if contains text, hide all others

    Try to filter on blank rows, and then hide. since Filter is an inbuilt function within excel, it would work faster regardless of row numbers.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Show row if contains text, hide all others

    Hi,

    I don't understand your difficulty since your column R formula seems to be giving you what you want (i.e. where the text in J1 exists somewhere in the Q cell) and hence just filter column R.

    If you're looking for an exact match then simply

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  6. #6
    Registered User
    Join Date
    03-30-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Show row if contains text, hide all others

    Thanks for the replies

    I got colum R to give me what i wanted, by it wasn't autoimatically hiding or unhiding the rows.

    After much playing around last night i did get it to work.

    I had to put the following code in the Sheet1 code at the end of the current Worksheet_Change code

    Please Login or Register  to view this content.
    And then created a HideRows Macro in Module1 with the following code:

    Please Login or Register  to view this content.
    Proabably not the neatest code in the world, but it works.

    Thanks again for your help guys.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Show row if contains text, hide all others

    Hi,

    This sort of request really should be a FAQ. I see it time and time again and looping just isn't the best way of doing this sort of thing.

    Whenever you find yourself creating a loop step back a bit and consider if there isn't a more efficient way. Loops should only be used as a last resort since they can be very slow particularly when many rows are involved.

    The fastest and most efficient way I know of doing this is to use an autofilter and filter for whatever is the relevant criteria. Then select all the filtered rows using the .SpecialCells(xlCellTypeVisible) construct, delete them all, finally remove the autofilter.

  8. #8
    Registered User
    Join Date
    03-30-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Show row if contains text, hide all others

    I would have used an autofilter, but i'm limited to excel 2003 at work and couldn't work out how to do that for a column of text that "included" a particular phrase, as opposes to matching whole cells (hence why i was posting here in the first place )

    I could easily get it done at home using excel 2010, but 2003 i couldn't get if to filter to all cells containing "xyz" anywhere in the cell.

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Show row if contains text, hide all others

    Hi,

    Don't forget that you can always use the wild card character * to find a particular string of characters in another string. e.g.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    where A1 contains say "Hawk" and B1 contains say "Seahawk". You can wrap the find in an IF(ISERROR()) function to set the result of the find to say either "Hide", or "Show" for that row and then just filter for the word 'Show".

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Hide/Show Textboxes
    By john55 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-06-2013, 03:22 PM
  2. Show/Hide charts
    By Myrvold90 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2012, 04:40 PM
  3. VBA hide row based on pull down with button to toggle show/hide
    By myronr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2012, 06:07 PM
  4. [SOLVED] Toggle text Show/Hide Macro
    By theghost in forum Excel General
    Replies: 2
    Last Post: 04-12-2012, 02:41 PM
  5. Show/Hide columns by checkbox and cell text
    By ksmoore in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-09-2010, 02:20 PM

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