+ Reply to Thread
Results 1 to 13 of 13

Hide Row Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    01-09-2018
    Location
    Cincinnati, Ohio
    MS-Off Ver
    2016
    Posts
    7

    Hide Row Macro

    I have a cell that has a list in it which has the options: regular, extended, regular and extended. I would like the row below this list to only be visible if the previous mentioned cell has "regular and extended" selected. I asked a coworker that has excel experience to take a look at it and he said he couldn't get it to run.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Hide Row Macro

    Untested in the absence of your workbook but something like the following in a SheetChange event macro.

    First name the cell that contains the drop down. It future proofs things for when you inevitably add some rows or columns above or to the left.
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Intersect(Target, Range("mydropdown")) Is Nothing Then
            If LCase(Target) = "regular and extended" Then
                Target.Cells(2, 1).EntireRow.Hidden = False
            Else
                Target.Cells(2, 1).EntireRow.Hidden = True
            End If
    
        End If
    End Sub
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    01-09-2018
    Location
    Cincinnati, Ohio
    MS-Off Ver
    2016
    Posts
    7

    Re: Hide Row Macro

    This is the code that I have come up with but it won't run. Doesn't give any errors, just doesn't run.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Worksheets("Input").Range("Post.Top.Bracket.Type").value = "REGULAR" Then
    Rows("165:165").EntireRow.hidden = True
    ElseIf Worksheets("Input").Range("Post.Top.Bracket.Type").value = "Extended" Then
    Rows("165:165").EntireRow.hidden = True
    ElseIf Worksheets("Input").Range("Post.Top.Bracket.Type").value = "Regular and Extended" Then
    Rows("165:165").EntireRow.hidden = False

    End If
    End Sub

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Hide Row Macro

    [QUOTE=Joe.RBI;4817504]This is the code that I have come up with but it won't run. Doesn't give any errors, just doesn't run.


    Why are you not following the example I gave and ignoring the advice? There is no need to name the sheet since you are using a sheet change event. The sheet name is irrelevant.

    You are also hard coding a cell reference. That's not good practice. You were advised to use a range name.

  5. #5
    Registered User
    Join Date
    01-09-2018
    Location
    Cincinnati, Ohio
    MS-Off Ver
    2016
    Posts
    7

    Re: Hide Row Macro

    [QUOTE=Richard Buttrey;4817545]
    Quote Originally Posted by Joe.RBI View Post
    This is the code that I have come up with but it won't run. Doesn't give any errors, just doesn't run.


    Why are you not following the example I gave and ignoring the advice? There is no need to name the sheet since you are using a sheet change event. The sheet name is irrelevant.

    You are also hard coding a cell reference. That's not good practice. You were advised to use a range name.
    I'm not sure I am following you. At no point did I ignore any advice, I tried your code and only changed the range value to the desired cell name. What do you mean by "hard coding a cell reference"? I have a named cell that has a list with three options that reference a separate tab.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Hide Row Macro

    Hello
    Try this code in worksheet module
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$E$2" Then
            If Target.Value = "regular and extended" Then
                Rows(Target.Row + 1).Hidden = False
            Else
                Rows(Target.Row + 1).Hidden = True
            End If
        End If
    End Sub
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  7. #7
    Registered User
    Join Date
    01-09-2018
    Location
    Cincinnati, Ohio
    MS-Off Ver
    2016
    Posts
    7

    Re: Hide Row Macro

    Quote Originally Posted by YasserKhalil View Post
    Hello
    Try this code in worksheet module
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$E$2" Then
            If Target.Value = "regular and extended" Then
                Rows(Target.Row + 1).Hidden = False
            Else
                Rows(Target.Row + 1).Hidden = True
            End If
        End If
    End Sub
    I tried this and couldn't get it to run either. It worked on the test file you sent but won't run on the spreadsheet in question.

  8. #8
    Registered User
    Join Date
    01-09-2018
    Location
    Cincinnati, Ohio
    MS-Off Ver
    2016
    Posts
    7

    Re: Hide Row Macro

    Additional information:

    The workbook has 5 tabs: INPUT, FIELDLIST, SEQUENCE, TABLE, Components
    The desired tab I am trying to run this in is the "INPUT" Tab.

    The cell that has the dropdown list in it is B164 but has been renamed to "POST.TOP.BRACKET.TYPE"
    The row I would like to hide is 165.

    There are multiple other macros working in this workbook but for some reason, I am unable to get any variation of this macro to run.

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Hide Row Macro

    It will be better to upload sample of your workbook ..

  10. #10
    Registered User
    Join Date
    01-09-2018
    Location
    Cincinnati, Ohio
    MS-Off Ver
    2016
    Posts
    7

    Re: Hide Row Macro

    The workbook is larger than 1,000kb file size limit. Is there an alternate way to attach it?
    Last edited by Joe.RBI; 01-09-2018 at 04:36 PM.

  11. #11
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Hide Row Macro

    copy your original file and delete most of the rows and also delete the sheets that doesn't relate to your request. Then compress the file with winrar and upload it

  12. #12
    Registered User
    Join Date
    01-09-2018
    Location
    Cincinnati, Ohio
    MS-Off Ver
    2016
    Posts
    7

    Re: Hide Row Macro

    Here is the zip file with most unnecessary info removed.
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Hide Row Macro

    Remove the filter then put the code in worksheet module
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.address = "$B$164" Then
            If LCase(Target.value) = "regular and extended" Then
                Rows(Target.Row + 1).hidden = False
            Else
                Rows(Target.Row + 1).hidden = True
            End If
        End If
    End Sub

+ 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 Visibility hide and unhide menu using macro ?
    By jasond1992 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-30-2015, 09:05 PM
  2. Hide/Show other macro buttons with a macro button
    By nohero in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2011, 09:24 AM
  3. Hide row macro
    By hrhittn23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2010, 04:57 PM
  4. conflict between auto save&close macro and show/hide sheets macro
    By alexandruc in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-18-2009, 11:56 AM
  5. Hide Macro
    By OfficeBitty in forum Excel General
    Replies: 3
    Last Post: 12-19-2006, 03:58 AM
  6. Hide Macro's in Toolbar / Macro's list
    By sparx in forum Excel General
    Replies: 2
    Last Post: 05-06-2006, 03:53 PM
  7. [SOLVED] hide macro
    By GM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-27-2005, 12:06 PM

Tags for this Thread

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