+ Reply to Thread
Results 1 to 21 of 21

Specific macro or VBA code to hide and unhide rows

Hybrid View

louvaek Specific macro or VBA code to... 11-05-2014, 11:12 AM
Olly Re: Specific macro or VBA... 11-05-2014, 11:36 AM
louvaek Re: Specific macro or VBA... 11-05-2014, 11:43 AM
jaslake Re: Specific macro or VBA... 11-05-2014, 11:49 AM
louvaek Re: Specific macro or VBA... 11-05-2014, 12:23 PM
louvaek Re: Specific macro or VBA... 11-14-2014, 04:38 AM
jaslake Re: Specific macro or VBA... 11-14-2014, 01:36 PM
louvaek Re: Specific macro or VBA... 11-16-2014, 07:22 PM
jaslake Re: Specific macro or VBA... 11-16-2014, 08:34 PM
louvaek Re: Specific macro or VBA... 11-17-2014, 07:36 AM
  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:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim c As Range
        If Not Intersect(Target, Range("B12:B17")) Is Nothing Then
            Range("B13:B17").EntireRow.Hidden = True
            For Each c In Range("B12:B17")
                If Not IsEmpty(c) Then c.Resize(2, 1).EntireRow.Hidden = False
            Next c
        End If
    End Sub
    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
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
      Dim OldValue As String, NewValue As String
      If Target.Cells.Count > 1 Then Exit Sub
      If Not Target.Column = 2 Then Exit Sub
      With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Undo
        OldValue = Target.Value  'store old value
        If Not OldValue = "" Then
          .Undo
          .ScreenUpdating = True
          .EnableEvents = True
          Exit Sub
        Else
          .Undo
          NewValue = Target.Value     'store new value
          Range(Target.Address).Offset(1, 0).EntireRow.Hidden = False
          .EnableEvents = True
          .ScreenUpdating = True
        End If
      End With
    End Sub
    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

    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.

  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

    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.

  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

    Jaslake,

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

    Grt
    Kristof

  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

    Been a busy Family weekend...

  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

    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