+ Reply to Thread
Results 1 to 11 of 11

Auto Hide and Unhide Rows Based

  1. #1
    Registered User
    Join Date
    12-02-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    6

    Auto Hide and Unhide Rows Based

    Hi, I am on this project which needs a VB code which automatically hide or unhide rows based from a value on a certain cell. I have to admit that I am not that proficient in VB Codes and Macro and any help would be highly appreciated. I have tried the following code below:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("C12").Value = CVErr(xlErrNum) Then
    Rows("1:13").EntireRow.Hidden = True
    Else
    Rows("1:13").EntireRow.Hidden = False
    End If
    End Sub


    Unfortunately, I am only successful in hiding the rows and not in unhiding it after I input data on another sheet (TallySheet). I attached a file of my project, and the worksheet I am working on is named Summary. Hoping for your help guys. Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Auto Hide and Unhide Rows Based

    Hi,
    Am i correct in guessing that the C12 cell with the value is on the Tally sheet and the rows you want to hide and unhide is on the Summary sheet?
    If so then I think the following code will do what you need:

    Please Login or Register  to view this content.
    Just right click on the tally sheet and select "View code" and paste the above code in the active window

    Hope this helps
    Mike
    Last edited by moonsaga; 12-03-2013 at 12:20 PM.

  3. #3
    Registered User
    Join Date
    12-02-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Auto Hide and Unhide Rows Based

    Quote Originally Posted by moonsaga View Post
    Hi,
    Am i correct in guessing that the C12 cell with the value is on the Tally sheet and the rows you want to hide and unhide is on the Summary sheet?
    Hi, thanks for the clarification C12 Cell is also in the Summary sheet. All sheets are somewhat dependent on each other except for the TallySheet. All I need to change is the TallySheet and the rest will just automatically calculate everything from there. However I want to hide some rows on the Summary Sheet which have the #Num! error from which I choose C12 which is the General Average, thereby hiding its entire table. If I get the correct VB code I'll also be using it so I can use it for the remaining tables below C12. Again thanks for the clarification.

  4. #4
    Registered User
    Join Date
    12-02-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Auto Hide and Unhide Rows Based

    Moonsaga thanks for the code, however, I need to apply the VB Code on the same sheet or in the Summary Sheet where C12 Cell is located and Entire Rows 1 to 13 hidden whenever the result in C12 = #NUM!. Thanks again.

  5. #5
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Auto Hide and Unhide Rows Based

    hmm.. I see that C12 on the summary sheet is linked to C83 on the median sheet and the median C83 is linked to C108 - BJ108 on the Tally sheet.
    so if one of the questions is not answered then the summary sheet will have the #NUM! in C12. so you want to hide the entire table in summary due to this error?

  6. #6
    Registered User
    Join Date
    12-02-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Auto Hide and Unhide Rows Based

    That is correct but in the case of C12 I want to hide rows 1 to 13 only, and I was hoping it will just be the same formula for the others from which if C21 have #NUM! result also I'll be hiding rows 14 to 22, for C31 hide rows 23 to 32, for C41 hide rows 33 to 42 and so forth. upon using the formula above from my first post:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("C12").Value = CVErr(xlErrNum) Then
    Rows("1:13").EntireRow.Hidden = True
    Else
    Rows("1:13").EntireRow.Hidden = False
    End If
    End Sub

    I was able to hide rows 1 to 13 but upon filling up data on the TallySheet to test it, unfortunately it did not automatically unhide and returned an error message from which I need to debug the line: If Range("C12").Value = CVErr(xlErrNum) Then.
    Last edited by Kosmik; 12-03-2013 at 01:43 PM.

  7. #7
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Auto Hide and Unhide Rows Based

    I will have to work on this some more .. just cant seem to get the code to unhide when a value is in cell C12..

  8. #8
    Registered User
    Join Date
    12-02-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Auto Hide and Unhide Rows Based

    Quote Originally Posted by moonsaga View Post
    I will have to work on this some more .. just cant seem to get the code to unhide when a value is in cell C12..
    Thanks! That's also my problem whenever a value is present in C12 it does not unhide. That is why I posted it here for possible solutions.

  9. #9
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Auto Hide and Unhide Rows Based

    I think i got it working now...
    Please Login or Register  to view this content.
    the above code will hide the row range when there is the #NUM! error in C12 of the Summary sheet and if there is no #NUM! error in C12 on the Summary sheet it will unhide the row range.
    I hope this works for you. let me know.

  10. #10
    Registered User
    Join Date
    12-02-2013
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Auto Hide and Unhide Rows Based

    Wow this is great thanks a lot. It worked like a charm! Thanks for your assistance.

  11. #11
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Auto Hide and Unhide Rows Based

    Your welcome.

+ 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. Auto Hide/Unhide rows in Excel based on radio button selection
    By awill110 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-30-2013, 03:05 PM
  2. Auto Hide & Unhide Rows Upon Sheet Selection
    By Sleeper in forum Excel General
    Replies: 4
    Last Post: 01-24-2013, 02:00 PM
  3. Auto Hide/Unhide rows in Excel based on formula result in a column
    By crozierk in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-12-2012, 08:02 AM
  4. Auto hide/unhide based on input
    By UnSpoknOne in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-03-2011, 06:11 PM
  5. 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