+ Reply to Thread
Results 1 to 21 of 21

Conditional Hide/Unhide Rows

  1. #1
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Conditional Hide/Unhide Rows

    Hi All,

    I have the following spreadsheet:

    I have a cell (e.g. B11) in which I have a drop-down menu with the numbers 1-10.
    Below this cell I have 10 blocks of rows. Each block contains a number of rows (say 7). E.g. rows 12-18; rows 19-25; rows 26-32; rows 33-39 etc. All these rows are currently hidden.

    Now I want the following to happen: After selecting a number (say 4) from this dropdown menu I want to the first 4 blocks of rows (e.g. rows 12-39) to appear. When I would select 2 from the dropdown menu, I want the first 2 blocks of rows to appear (e.g. row 12-25). Etc.

    Would this be possible without Macro (through some sort of conditional formatting?)? If I would need a macro, could anyone help me with this?

    Thanks for your help!

    Eduard

  2. #2
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Conditional Hide/Unhide Rows

    Please Login or Register  to view this content.
    this goes into the worksheet module which contains the rows which shall be hidden etc. My assumption was that the dropdown menu is created with the data validation option (not activex or form)
    Last edited by Bishonen; 11-09-2012 at 06:10 AM.
    If you think that my answer was helpful, please click on the "Add to this user's Reputation" button.

  3. #3
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    Thanks, I have inserted the macro, but can't seem to get it working. What am I doing wrong? See attachedTest.xlsm

    Thanks,

    Eduard

  4. #4
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Conditional Hide/Unhide Rows

    as i wrote before :
    this goes into the worksheet module which contains the rows which shall be hidden etc
    So please delete the module1 and put it into the worksheet module (Blad2 in your case).

    The code below takes 0 into consideration as well(meaning all rows will be hidden).

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    Thanks, but still not working. Feel very stupid... See upload.

    If, I want to show text instead of a 0 when all rows are hidden, how should I change the Macro?

    Eduard
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Conditional Hide/Unhide Rows

    you still have it in the wrong worksheet You have changed the names of the property in the vba section and thus made it unclear (even for yourself) where to put the code. The worksheet named "Blad2" has the name Blad3 in VBA.

    Please see the file attached.

    Copy of Test2.xlsm

    And what exactly do you mean by
    I want to show text instead of a 0 when all rows are hidden, how should I change the Macro?
    ? Do you mean you'd like to unhide all rows? Display a msgbox with a text? Or something entirely different?

  7. #7
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    Thanks! It works now... When all rows are hidden, cell B11 will show the text "Maak je keuze...". This messes up the macro. Any solution?

  8. #8
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Conditional Hide/Unhide Rows

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    Thanks, this works. But when I select a number and go back to the text"("Maak je keuze..."), it returns error 13. When tracking the error, it says the error is in "Range(Cells(12, 1), Cells(13 + i * cRows, 1)).EntireRow.Hidden = False". Any idea what could cause the error?

  10. #10
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Conditional Hide/Unhide Rows

    There's quite a misunderstanding going on here I thought that if someone choses "0", the text "Maak je keuze..." should appear in the cell (you can try it out, it works). You apparently meant something else: did you mean that when seomeone puts "Maak je keuze...", all specified rows should be hidden until a number is entered in the cell? If so:

    Please Login or Register  to view this content.
    If this still isn't working out the way you'd like it, then please elaborate a bit more on what should happen when ^^

  11. #11
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    If I want to add multiple copies of the same macro (different ranges, same worksheet), how should I change the name "Private Sub Worksheet_Change(ByVal Target As Range)"?

  12. #12
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    Strange, something went wrong. I also posted a reply thanking you for your help and saying everything works smoothly. I'll try again: Thanks!

    But if I want to add multiples versions of this macro to the same worksheet, how should I change the name "Private Sub Worksheet_Change(ByVal Target As Range)"? Just adding a number returns an error.

    Thanks in advance for final piece of my puzzle!

  13. #13
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Conditional Hide/Unhide Rows

    AFAIK you can't do it like this:

    Please Login or Register  to view this content.
    You would have to include all actions within one on event procedure:

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    Thanks, but where to start the macro? The "i" and cell B11 isn't the same for all macros?

  15. #15
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    Copy Testfile.xlsmHi, as you (Bishonen) requested, here is an update to the thread. I have tried the following code, but nothing happens on either cell (C11 and/or C140). I will need approximately 10 macros in the same worksheet, they will have different i values, how do I change that? The code below assumes the same i value.

    Thanks!

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Edward HS; 11-12-2012 at 10:22 AM.

  16. #16
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Conditional Hide/Unhide Rows

    please swap the whole code with this one:

    Please Login or Register  to view this content.
    Very little changes had to be done. Please be aware that the file and the code use sometimes a different phrase for "hide all": Kies#: and Kies #:.

    This will ofc generate an error.

  17. #17
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    Hi,

    How do I alter the macro above that instead of numbers, it works on written text (I have a drop down menu with 4 options).

    For example, if you type "Optie 1 Verzoek" it hides rows 12-50; if you type "Andere mogelijkheid" it hides rows 52-100; if you type "Dit kan ook" it hides rows 12-100, and finally if you type "Of dit" it hides rows 12-150.

    Thanks for the help!

    FYI: I'm working with the following macro from the text above:

    'macro number 1 - Type Aanvraag
    If Not Intersect(Target, gRange) Is Nothing Then
    Application.ScreenUpdating = False
    If aRange = "Kies#:" Then
    Application.EnableEvents = False
    Range(Cells(11, 1), Cells(10 + k * 10, 1)).EntireRow.Hidden = True
    Application.EnableEvents = 1
    Exit Sub
    Else
    Range(Cells(12, 1), Cells(11 + k * 10, 1)).EntireRow.Hidden = True
    Range(Cells(12, 1), Cells(11 + k * cRows, 1)).EntireRow.Hidden = False
    End If

  18. #18
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    Anyone that can help me on the question above? Any help would be greatly appreciated!
    Thanks

  19. #19
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    *Bump no response*

  20. #20
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Conditional Hide/Unhide Rows

    @Edward HS,

    Administrative Note:
    • We would love to continue to help you with your query, but first, before we can proceed…
    • Please see Forum Rule #3 about the proper use of code tags and adjust accordingly...
    HTH
    Regards, Jeff

  21. #21
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Re: Conditional Hide/Unhide Rows

    My apologies, forgot to use the brackets. Here is a second try.

    Hi,

    How do I alter the macro above that instead of numbers, it works on written text (I have a drop down menu with 4 options).

    For example, if you type "Optie 1 Verzoek" it hides rows 12-50; if you type "Andere mogelijkheid" it hides rows 52-100; if you type "Dit kan ook" it hides rows 12-100, and finally if you type "Of dit" it hides rows 12-150.

    Thanks for the help!

    FYI: I'm working with the following macro from the text above:

    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)

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