+ Reply to Thread
Results 1 to 20 of 20

Auto Hide/Unhide Rows Anytime Drop Down List Changes

  1. #1
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Auto Hide/Unhide Rows Anytime Drop Down List Changes

    I'm very new to macros. I have an income statement by month with an ActiveX Combobox containing the various departments. On a separate sheet called "Analysis" (in the same format minus the drop down list) is calculating % of revenue. In column P is a formula to give me "1" if any month (Jan-Dec) contains a cost that is greater than 5% and "0" if not. I want to see every row(cost) that contains 5% or greater. I want all of the rows within my range to hide or unhide anytime the user makes a new selection from the drop down list. I have some codes that work but not automatically. Every time I make a different selection I have to open up the vba and hit F5 to run it. Here are 2 codes I've tried and work but do not auto hide/unhide when a new selection from drop down list is made. Any help will be GREATLY appreciated.

    Sub HideRows()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    BeginRow = 22
    EndRow = 300
    ChkCol = 16

    For RowCnt = BeginRow To EndRow
    If Cells(RowCnt, ChkCol).Value = "" Then
    Cells(RowCnt, ChkCol).EntireRow.Hidden = True
    ElseIf Cells(RowCnt, ChkCol).Value = 1 Then
    Cells(RowCnt, ChkCol).EntireRow.Hidden = False
    End If
    Next RowCnt
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic

    End Sub

    ----------------------------------------------------------------------

    Private Sub Worksheet_Activate()
    If MyVal = "" And [B11] <> "" Then MyVal = [B11] & ""
    End Sub


    Private Sub Worksheet_Calculate()
    Dim CELL As Range


    If [B11] <> MyVal Then
    For Each CELL In Range("P22:P300")
    Rows(CELL.Row).Hidden = CELL = 0
    Next CELL
    MyVal = [B11] & ""
    End If

    End Sub
    Last edited by jkle4596; 09-25-2015 at 09:43 AM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Hi Jide,

    Welcome to the Forum!

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    BTW:

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Is this correct way of posting code? Attached is a desensitized sample of what I am trying accomplish. There are 2 codes in the vba.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Hi jkle4596

    Welcome to the Forum!!!

    Place this Code in the Sheet Module for Monthly Trend (Right Click on the Tab ---> View Code ---> Paste the Code into the Right Hand Window.

    Each time the ConboBox is changed the Code will fire. The Code Filters on Column P of Sheet Analysis (displays only the 1's).

    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Works like a charm. The only thing I ended up needing was to skip certain rows for my headers of the report and spacing but to work around it I just put a "1" in a few places in column P. Thanks a lot!

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    You're welcome...glad I could help. Thanks for the Rep.

  7. #7
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Ok one more thing...how can I lock and password protect this sheet preventing the end user from manipulating it? This is kind of important for me to have it locked. At it's current state the macro will not work.

    I currently have this password macro in place for the entire workbook.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    The password macro I have is needed so that the end user can ungroup the rows of the consolidated income statement for the ability to see the detail. Maybe make my password macro only for the 1 sheet containing the income statement?

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Hi jkle4596

    Try this...
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    It works but now every time I make a new selection from the ActiveX combobox list the row/column section of the window jumps like it freaks out for a sec. Not really what I would like the end user (management) to become irritated with.

    I even deleted the other macro, saved and reopened.

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Hi jkle4596

    Add a couple lines of Code...
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    I'd like to think it's MS 2013. I have had issues with it before. That's why I have a new computer as of today. Can you think of any kind of workaround?

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    See Post #11

  14. #14
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Thank you very much. It still blinks slightly but I don't think it'll be a problem. You've been a tremendous help!

  15. #15
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Ok I'm sorry. I can't take the slight blinking. You've helped so much but I don't understand why another code below that was already in there works fine with no blinking. Any other suggestions before I try another route like maybe a separate workbook...

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Or maybe both codes trying to do the same thing are causing it to blink? The code I just gave is for the entire workbook.

  17. #17
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Hi jkle4596

    The Code you presented only runs on Workbook Open...never again until after Workbook is Closed and then re-opened. So, no, they are not in conflict.

    What flicker I see is negligible. The only thing I can recommend is Activating the Results Sheet (Analysis) because that's what "management" expects to see...sorry...

    Please Login or Register  to view this content.

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Or, try this, see if it's any better...
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    09-25-2015
    Location
    Louisiana
    MS-Off Ver
    MS Office 2013
    Posts
    29

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Still the same. What if the macro was placed on the "Analysis" sheet to run based on the change of a single cell that is linked up to the income statement with the combobox?

  20. #20
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Hide/Unhide Rows Anytime Drop Down List Changes

    Hi jkle4596

    Sure, try it. If you need help please explain, specifically, what you have in mind.

+ 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/Unhide cells based on drop-down list
    By Savvy25 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2014, 02:36 AM
  2. Hide-Unhide rows on multiple worksheets based on value of a drop down list
    By clo2peter in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-10-2014, 08:32 AM
  3. [SOLVED] How to auto hide/unhide rows based on value of sum
    By wesleeptheylive in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-27-2013, 04:34 PM
  4. [SOLVED] Auto Hide and Unhide Rows Based
    By Kosmik in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-05-2013, 10:09 AM
  5. [SOLVED] hide or unhide rows based on text within a drop down list
    By souimet in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2013, 01:32 AM
  6. Hide/unhide columns based on the drop down list value
    By vagif in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-16-2012, 02:13 AM
  7. Auto Hide or Unhide rows.
    By Michael S in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-19-2009, 06:04 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