+ Reply to Thread
Results 1 to 21 of 21

Specific macro or VBA code to hide and unhide rows

  1. #1
    Registered User
    Join Date
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Specific macro or VBA code to hide and unhide rows

    Hey everyone,

    This is my first question here, but I used the forum a lot before. Each time I found the answer, so I have good hopes for this one too
    I found a couple of similar threads about this, but none worked for me (probably because I don't know how to adapt the code).

    I have an empty col A
    I have a col B with names in it.
    I have a lot of other col from C to ... but those don't really mather here

    In col B, beside names, I have empty cells too ... These are for the users to add names.
    e.g.
    B3 to B11 = names already filled in
    B12 to B17 = empty cells

    My question about this is:

    If B12 is empty, B13 till B17 should be hidden rows.
    From the moment someone fills in B12, B13 shoud auto unhide, B14 till B17 stays hiden.
    If someone wants to fill in an extra name in B13 too, B14 = unhide, B15 till B17 = hiden
    And so on, and so on ... Note: B18: always visible because that's a new set of values that always must be visible.

    Hope that someone gets me, and that my English wasn't too bad
    PS: it's for Excel that I'm using @ work, so it's 2007.
    The attachment is another version of Excel, that's my home edition.

    Thanks in advance !

    Kristof
    Attached Files Attached Files
    Last edited by louvaek; 11-05-2014 at 11:28 AM.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Specific macro or VBA code to hide and unhide rows

    Try:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Specific macro or VBA code to hide and unhide rows

    Wow that works like a charm Thanks man !!!

  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: Specific macro or VBA code to hide and unhide rows

    Hi louvaek

    Welcome to the Forum!!!

    Here's another approach
    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
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Specific macro or VBA code to hide and unhide rows

    Hi Jaslake,

    I've tried yours but it does nothing.
    I assume it's the same way I should insert the code? (right click tab, view code, copy paste)?

    Grt
    Kristof

  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: Specific macro or VBA code to hide and unhide rows

    Hi louvaek

    Here's your File with the Code embedded...
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Specific macro or VBA code to hide and unhide rows

    Thanks Jaslake.

    But something doesn't work. If I add a value, a row unhides indeed. But if I delete it again, it doesn't hide again
    What's the diff. between your solution and Olly's? Which one should I use if I really have lot's of names in that list, and lot's of names that should be added by users?

    Grtz
    Kristof

  8. #8
    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: Specific macro or VBA code to hide and unhide rows

    Hi Kristof

    The downside of Olly's Code is that the range of Cells is fixed. If that works for you then use it.
    Please Login or Register  to view this content.
    I'll look at this
    But if I delete it again, it doesn't hide again

  9. #9
    Registered User
    Join Date
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Specific macro or VBA code to hide and unhide rows

    Well Olly's works, but I just tested something and the code missed it effect afterwards. I deleted a row (a name that should not longer be in the list) in the B3:B11 range.
    After that, the code doesn't work anymore in B12 (B13 : B17 still works). If I delete another row, B13 doesn't work anymore.

    So Olly's code is clean and simple, but should be manually changed each time I delete a row in the sheet.
    I guess the code should have something with 'row()' included? I know a lot about formula's, but I am a real VBA newbie :-)

  10. #10
    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: Specific macro or VBA code to hide and unhide rows

    Hi Kristof

    There's a bit of mind numbing logic going on here, see if this works as required
    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Specific macro or VBA code to hide and unhide rows

    Jaslake,

    The unhiding works perfect. If I add a value in B13, B14 shows. If I add a value in B15, B15 shows.
    But when I delete B14, B15 does not unhide, it's B14 that hides ... and B15 stays visible.

  12. #12
    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: Specific macro or VBA code to hide and unhide rows

    Hi Kristof

    When you say "delete", are you deleting a Row or are you clearing the contents of the Cell?

  13. #13
    Registered User
    Join Date
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Specific macro or VBA code to hide and unhide rows

    If I delete the value (or values) in the B12:B17 range.
    Deleting rows works fine with your VBA code.

  14. #14
    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: Specific macro or VBA code to hide and unhide rows

    Hi Kristof

    If I understand the issue
    Please Login or Register  to view this content.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Specific macro or VBA code to hide and unhide rows

    That one did it
    Thanks man !!!

    Add Rep +1

  16. #16
    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: Specific macro or VBA code to hide and unhide rows

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

  17. #17
    Registered User
    Join Date
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Specific macro or VBA code to hide and unhide rows

    Jaslake,

    I had to change my sheet and I don't know what I have to change in your code to make it work again, because now it doesn't :s
    In fact, it no longer has to check one column, it has to check five columns.

    Row 11 = always visible, value is fixed
    Row 12 = always visible, is empty by default (user can input name or names in the range C12:G12
    Row 13 = NOT visible, unless user has made an input in one (or more or all) of these cells: C12, D12, E12, F12 or G12
    Row 14 = NOT visible, unless user has made an input in one (or more or all) of these cells: C13, D13, E13, F13 or G13
    ...
    Row 21 = NOT visible, unless user has made an input in one (or more or all) of these cells: C20, D20, E20, F20 or G20
    Row 22 = always visible, value is fixed

    Same for all the other empty lines in the sheet.

    I also have a VBA that stopped working when I copy pasted your code (the VBA code to 'UPPERCASE input user)

    Hope you can help me once again I'll attach my sheet ...
    I would be very thankfull

    Grt
    Kristof
    Attached Files Attached Files
    Last edited by louvaek; 11-14-2014 at 04:41 AM.

  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: Specific macro or VBA code to hide and unhide rows

    Hi Kristof

    This is a major rewrite and you've marked your Thread as SOLVED.

    I'd suggest you get your Worksheet where you need it to be (to avoid rewrites) then start a new Thread for these new requirements.

    Having done so, if you wish, you may PM me with a link to your new Thread and I'll look at it.

  19. #19
    Registered User
    Join Date
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Specific macro or VBA code to hide and unhide rows

    Jaslake,

    I did PM you, and started the new thread yesterday.

    Grt
    Kristof

  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: Specific macro or VBA code to hide and unhide rows

    Hi Kristof

    Been a busy Family weekend...

  21. #21
    Registered User
    Join Date
    10-17-2013
    Location
    Ardooie
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Specific macro or VBA code to hide and unhide rows

    No prob

+ 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. use macro to find and replace specific code in vba
    By hopefulhart in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2014, 09:46 AM
  2. [SOLVED] Code to run a Macro on a specific day of the week at a specific time.
    By mjfox52610 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2013, 11:40 PM
  3. [SOLVED] Macro code to Copy specific rows into specific columns
    By macrofan2012 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-11-2012, 11:24 AM
  4. vba code to apply a macro to a specific tab
    By 2seas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-09-2012, 02:03 PM
  5. Assistance with Creating a Specific Macro using VBA code
    By Pbeer in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-17-2008, 05:35 AM

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