+ Reply to Thread
Results 1 to 8 of 8

VBA Help to UNHIDE rows in a sheet based on a cell value

  1. #1
    Registered User
    Join Date
    06-14-2017
    Location
    London, England
    MS-Off Ver
    365
    Posts
    7

    VBA Help to UNHIDE rows in a sheet based on a cell value

    Hi, I am really new to this and need help in unhiding some rows on my sheet based on the cell value of another cell which has a drop down validation list. I have already added in code for the same sheet that works for another section where I want this, but cant get the next one to work. So in my example, if cell C41 has the drop down value "012 - Alcoholic Beverages", then i want rows "43:45" to become unhidden (currently manually hidden), if it is any other value or blank I need it to stay hidden. Code already pasted in is:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("B3").Value = "Food" Then
    Range("A41:A44").EntireRow.Hidden = True
    Else
    Range("A41:A44").EntireRow.Hidden = False
    End If
    End Sub

    Your simple resolution to this problem would be greatly appreciated!
    Thanks

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: VBA Help to UNHIDE rows in a sheet based on a cell value

    Hi hchahal, welcome to the forum! To make you code more readable, we ask that you select it, then click # on the Editing Toolbar. This wraps it in code tags, so it looks like the code below. Thanks.

    So, is this what you had in mind? Or do you want to loop through several check values, each with different associated rows?
    Please Login or Register  to view this content.
    Last edited by leelnich; 06-14-2017 at 12:26 PM.

  3. #3
    Registered User
    Join Date
    06-14-2017
    Location
    London, England
    MS-Off Ver
    365
    Posts
    7

    Re: VBA Help to UNHIDE rows in a sheet based on a cell value

    Hi Leelnich...thansks for the fast reply....This is not working for me. Not sure if I made it clear but the code I am already using I want that to stay as is for other rows to become unhidden when someone selects for for cell B3...when I try and add a further statement in using the same details but amendsing the cells and what should be false or true i get the run time error 40036.....any ideas? Thanks

  4. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: VBA Help to UNHIDE rows in a sheet based on a cell value

    Your approach should have worked. Could you post the code that produced the error, or better yet, attach a sample version of your workbook? NOTE: you may need to reverse True and False in the original code (mine AND yours) to get the desired result.

    To attach a workbook:
    Click Edit Post (or just start a new reply.)
    Click Go Advanced
    Scroll down to Manage Attachments and click.
    Now just Browse for your file, then click Upload. Simple!
    Last edited by leelnich; 06-14-2017 at 12:44 PM.

  5. #5
    Registered User
    Join Date
    06-14-2017
    Location
    London, England
    MS-Off Ver
    365
    Posts
    7

    Re: VBA Help to UNHIDE rows in a sheet based on a cell value

    Hi...see below for what I have, had to change the cells for the second part as I needed to add in more rows:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("B3").Value = "Food" Then
    Range("A40:A44").EntireRow.Hidden = True
    Else
    Range("A40:A44").EntireRow.Hidden = False
    End If
    End Sub
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("C54").Value = "012 - Alcoholic Beverages" Then
    Range("A56:A58").EntireRow.Hidden = False
    Else
    Range("A56:A58").EntireRow.Hidden = True
    End If
    End Sub

  6. #6
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: VBA Help to UNHIDE rows in a sheet based on a cell value

    Quote Originally Posted by hchahal View Post
    Please Login or Register  to view this content.
    You've defined TWO Worksheet_Change event procedures. Each worksheet only gets ONE. Remove the highlighted lines and do both checks within the same procedure.
    NOTE: If you have several checks to do, there are more efficient approaches to this task.
    Last edited by leelnich; 06-14-2017 at 01:40 PM.

  7. #7
    Registered User
    Join Date
    06-14-2017
    Location
    London, England
    MS-Off Ver
    365
    Posts
    7

    Re: VBA Help to UNHIDE rows in a sheet based on a cell value

    leelnich...works great now...I knew I was doing something simple wrong...typical, getting too old!. Many Thanks for your help and swift replies.

  8. #8
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: VBA Help to UNHIDE rows in a sheet based on a cell value

    Happy to help! If your question is answered, please go to Thread Tools up top and mark your thread as SOLVED. Thanks-Lee

    Please click the Add Reputation star below any helpful posts, and if you have your answer, mark your thread as SOLVED (Thread Tools up top). Thanks!-Lee

+ 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 or Unhide Rows on one sheet based on value entered in cell on another sheet
    By wfsteadman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2016, 07:30 PM
  2. Hide/unhide rows based on cell value of another sheet
    By Vivek2705 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2016, 07:55 AM
  3. Need Toggle Button to hide/unhide rows based on cell value in non concurrent rows
    By The Phoenix in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-13-2015, 10:49 AM
  4. Vb code to hide/unhide rows based on entries on another sheet
    By tcrjmom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2015, 01:15 PM
  5. Replies: 2
    Last Post: 09-22-2014, 12:52 PM
  6. [SOLVED] First unhide all rows - then hide rows based on specific cell value for a range of cells
    By robbiekh in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-22-2013, 05:46 PM
  7. Unhide rows based on cell value
    By Sky188 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-09-2012, 06:03 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