+ Reply to Thread
Results 1 to 9 of 9

Only show or hide certain rows based on the value in one column using VBA

  1. #1
    Registered User
    Join Date
    11-05-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    5

    Only show or hide certain rows based on the value in one column using VBA

    Hi all,

    Thank you for reading this thread.

    I am trying to use the commands to show or hide certain rows based on one column's value.

    The case here is:

    1. I have 10 people on a name list.
    2. 10 people have been assigned to 3 groups.
    3. Each person is unique and belongs to only one group.
    4. Each row has been randomly arranged, followed no A to Z, smallest to largest sequences. For example, Row 2, which is the very next row after the header, will have a name of Michael in Cell A2 and a group number 1 in Cell B2. Then for Row 3, it will have a name of Chris in Cell A3 and a group number 3 in Cell B3.

    I want to use below 2 methods to display the results I wanted on this sheet by either using a drop down list, or a Macro button:

    Using a drop down list
    1. Set up a drop down list with 3 values (group numbers), which of course they will be number 1, 2 and 3, and then with a value to be "ALL".
    2. After selected the value to be 1 in the drop down list, only the rows have people belonging to group number 1 will become visible. All other rows, except the header, will disappear/ be hidden.
    3. Then, after selected the value to be ALL in the drop down list, all rows will then show again, because I want to see every single row again.

    Using a Macro button
    1. Set up a Macro button to be named as Group Number.
    2. On the right side of this button, on the example sheet I have attached, leave a blank cell, which is F15, for the purpose of entering 4 values: 1, 2, 3, ALL.
    3. Then, I want to use this Macro button to have the same result as how I wanted by using the drop down list.
    4. For example, I have now entered "2" in F15. Then after I hit the Macro button "Group", it will automatically show every row that has a number 2 value in the B column, and then automatically hide all other rows.
    5. The reason why only rows that have a number 2 value need to show, is because I want to see who are the names/ people belong to group number 2, under B column.

    I have tried multiple codes but it seems not working at all.

    Would highly appreciate if anybody could look into this for me and again, thank you so much!!!
    Attached Files Attached Files

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Only show or hide certain rows based on the value in one column using VBA

    Hell aguopr,

    Welcome to this Forum!

    you could use the Code below for the Button on your Sheet.

    Please Login or Register  to view this content.
    Try the attached sample workbook.

    Regards.
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Registered User
    Join Date
    11-05-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    5

    Re: Only show or hide certain rows based on the value in one column using VBA

    Good morning Winon,

    Thank you soooo much for the reply!

    The code works perfectly!

    I apologize that I might have misinterpreted myself in the original post.

    Based on your codes, it seems

    1. The Macro button works based on a drop down list selection at A15.
    2. If the drop down list is to select "ALL", it will hide all the rows, no matter it is group 1, or 2, or 3.

    What I was looking for was:

    1. Have a drop down list working as a Macro button.
    For example, I was thinking it could possibly work like, if you select number 1 from the drop down list, then this whole sheet will only show rows have number 1 from column B.
    In this case, no Macro button is even needed - a drop down list would simply work.

    2. If there must be a Macro button to perform such, it should work based on a condition in cell F15, not A15.

    I am not sure if this can happen, but again Winon, thank you so much for your help!!!!

    Best regards,

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Only show or hide certain rows based on the value in one column using VBA

    Hell aguopr,

    Thank you for your feedback!

    I have revised the sample workbook, and you may now remove whatever you prefer.

    Regards.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-05-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    5

    Re: Only show or hide certain rows based on the value in one column using VBA

    Winon, you are an amazing magician!!! Thank you so much and this is exactly what I wanted!!!

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Only show or hide certain rows based on the value in one column using VBA

    Hi aguopr,

    You are welcome, glad I could help.


    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

    Regards.

  7. #7
    Registered User
    Join Date
    11-05-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    5

    Re: Only show or hide certain rows based on the value in one column using VBA

    Hi Winon, I just added a reputation to your post!

    I am re-working some of your codes on another sheet that I might request your help again, so I would prefer not to mark this thread as resolved.

    I may have to bother you again...

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Only show or hide certain rows based on the value in one column using VBA

    Hi aguopr,

    I am re-working some of your codes on another sheet that I might request your help again, so I would prefer not to mark this thread as resolved.
    That is fine with me, as long as any further requests are related to the same subject matter of this Thread.

    Regards.

  9. #9
    Registered User
    Join Date
    11-05-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    5

    Re: Only show or hide certain rows based on the value in one column using VBA

    Hi Winon,

    I finally figured out what I needed and have marked this thread as SOLVED.

    Thank you very much again and wish you have a wonderful day!

+ 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. Show rows based on Selection and hide rest of rows
    By Sanjibghosh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-20-2017, 10:27 AM
  2. Hide or Show rows based off value of cell in that row?
    By dancor31 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-17-2017, 01:38 PM
  3. Show Hide Rows based on cell value
    By Juicy2052 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-13-2015, 07:55 AM
  4. [SOLVED] Hide/show rows with 0 value in column D and E based on case selection
    By say0nara in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-31-2013, 06:34 AM
  5. [SOLVED] Hide/Show rows based on the value in a cell
    By PatRiot199 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-11-2012, 11:52 PM
  6. VBA code to hide/show rows based on value in each row
    By KEM4321 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2012, 01:19 PM
  7. Code to show/hide rows based on Y
    By Justinmih in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-03-2011, 06:12 PM

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