+ Reply to Thread
Results 1 to 6 of 6

Auto hide/unhide based on cell value

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-27-2013
    Location
    Nebraska
    MS-Off Ver
    Office 365
    Posts
    115

    Auto hide/unhide based on cell value

    I am trying to have Rows 6:8 hide/unhide depending on the value in cell B5 which I named Paint. After doing some searching on here I found some code that I thought would work. The Paint_Option sub runs properly when stepping through it, but I am struggling with making it run when B5 is updated.

    Sub Paint_Option()
    
        If Range("B5").Value = "Yes" Then
            [6:8].EntireRow.Hidden = False
        Else
            [6:8].EntireRow.Hidden = True
        End If
    
    
    End Sub
    
    Sub worksheet_change(ByVal target As Range)
    Set target = Range("B5")
        If target.Value = "Yes" Then
            Call Paint_Option
        End If
        
        If target.Value = "No" Then
            Call Paint_Option
        End If
    
    End Sub
    Thank you!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Auto hide/unhide based on cell value

    1. The code is
    Rows("6:8").EntireRow.Hidden = True
    2. You are over complicating your code.


    
    Sub worksheet_change(ByVal target As Range)
    
    If target.address <> "$B$5" then exit sub
        
    If target.Value = "Yes" Then
            Rows("6:8").EntireRow.Hidden = True
        Else
            Rows("6:8").EntireRow.Hidden = False
    End If
    
    End Sub
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    06-27-2013
    Location
    Nebraska
    MS-Off Ver
    Office 365
    Posts
    115

    Re: Auto hide/unhide based on cell value

    mehmetcik,

    Thank you for your quick reply. I tried changing the code to what you have, but the sheet is still not updating when B5 is updated. Is there something else that I am missing?

    Sub worksheet_change(ByVal target As Range)
        If target.Address <> "$B$5" Then Exit Sub
        If target.Value = "Yes" Then
            Rows("6:8").EntireRow.Hidden = True
        Else
            Rows("6:8").EntireRow.Hidden = False
        End If
    End Sub

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Auto hide/unhide based on cell value

    If B5 contains a formula, the Change event won't be triggered when it changes. Put that code in the Calculate event.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Auto hide/unhide based on cell value

    It works perfectly here.

    Where did you put the code?

    right click on your sheet name at the bottom of excel

    select view code

    paste the code into the module that opens and close it.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    06-27-2013
    Location
    Nebraska
    MS-Off Ver
    Office 365
    Posts
    115

    Re: Auto hide/unhide based on cell value

    mehmetcik,

    I did have the code in the wrong place, however after moving it to the correct location it still doesn't work for me. I downloaded the file you edited and the macro is not running whenever B5 is changed from either Yes or No. I am not sure what would be causing different results on this one. Is there setting that I need to enable? Other macros seem to be working correctly.

    Thank you!

+ 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. [SOLVED] auto hide and unhide rows based on formula result in a cell
    By Dena in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-13-2017, 05:46 PM
  2. Auto hide and unhide of columns based on a cell value
    By bala04msw in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-02-2016, 08:07 AM
  3. How to auto hide/unhide sheets in excel workbook based on cell input?
    By bensaps10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-02-2014, 09:57 AM
  4. [SOLVED] Auto hide/unhide row based on row above
    By wjwelch1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-14-2014, 02:10 PM
  5. [SOLVED] How to auto hide/unhide rows based on value of sum
    By wesleeptheylive in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-27-2013, 04:34 PM
  6. Auto Hide And Unhide Row Based On Empty Cell In Specific Range
    By jackgan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-26-2013, 09:18 AM
  7. Can I auto hide/unhide worksheets based on selected cell criteria.
    By cwashburn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2013, 04:06 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