Results 1 to 4 of 4

Thread: Hide Command Button

  1. #1
    Board Regular
    Join Date
    Jul 2018
    Location
    Auckland
    Posts
    308
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Hide Command Button

    Hi,

    I'm trying to hide a command button if cell D8 does not equal 1, 2, 3 or 4. D8 is a dropdown, so changes manually. I have the following code below (which may or may not work) but I'm having difficulty including it with my other code (also below) as I keep getting errors. Can someone help me piece the two together please?

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Application.ScreenUpdating = False
        If Range(D8).Value <> "1,2,3,4" Then
            Me.CommandButton1.Visible = True
        Else
            Me.CommandButton1.Visible = False
        End If
        Application.ScreenUpdating = True
    End Sub
    Code:
    Private Sub CommandButton1_Click()
    PDFRentalStmtNo1
    End Sub
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        
    If Not Intersect(Target, Range("No._Rentals")) Is Nothing Then
    
    
    If Target.Cells.CountLarge > 1 Then Exit Sub
    Select Case Target.Value
    
    
        Case "Please Select"
            Range("15:18,42:110,42:260").EntireRow.Hidden = True
            
        Case 1
            Range("15:18,42:110,42:260").EntireRow.Hidden = False
            Range("16:18,60:110,119:125,132:148,150:260").EntireRow.Hidden = True
            
        Case 2
            Range("15:18,42:110,42:260").EntireRow.Hidden = False
            Range("17:18,77:110,119:125,132:148,156:162,169:185,187:260").EntireRow.Hidden = True
            
        Case 3
            Range("15:18,42:110,42:260").EntireRow.Hidden = False
            Range("18:18,94:110,119:125,132:148,156:162,169:185,193:199,206:222,224:260").EntireRow.Hidden = True
            
        Case 4
            Range("15:18,42:110,42:260").EntireRow.Hidden = False
            Range("119:125,132:148,156:162,169:185,193:199,206:222,230:236,243:259").EntireRow.Hidden = True
    
    
    End Select
    End If
    
    
    Dim rng As Range
    Set rng = Intersect(Target, [B118:B125,B131:B148,B155:B162,B168:B185,B192:B199,B205:B222,B229:B236,B242:B259])
    If Not rng Is Nothing Then rng(2, 1).EntireRow.Hidden = False
    End Sub
    
    
    
    
    Sub Rental_Stmt_No1()
    With Sheet80
    .Asset_Hide_Prop_1
    .Asset_Hide_Chat_1
    End With
    PDFRentalStmtNo1
    End Sub
    
    
    Sub Rental_Stmt_No2()
    With Sheet81
    .Asset_Hide_Prop_2
    .Asset_Hide_Chat_2
    End With
    PDFRentalStmtNo2
    End Sub
    
    
    Sub Rental_Stmt_No3()
    With Sheet82
    .Asset_Hide_Prop_3
    .Asset_Hide_Chat_3
    End With
    PDFRentalStmtNo3
    End Sub
    
    
    Sub Rental_Stmt_No4()
    With Sheet83
    .Asset_Hide_Prop_4
    .Asset_Hide_Chat_4
    End With
    PDFRentalStmtNo4
    End Sub

  2. #2
    Moderator mole999's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    9,857
    Post Thanks / Like
    Mentioned
    16 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Hide Command Button

    I would think
    If Range(D8).Value <> "1,2,3,4" Then is your issue

    so

    If Range(D8).Value <> "1" OR If Range(D8).Value <> "2" Then

    OR

    If Range(D8).Value => "1" AND If Range(D8).Value <= "4" Then

    might be the way to go
    • Yes I know there are better ways to do it. I just wish I knew them. - 97, 2003, 2007, 2010, 2013, 2016 & 2019
    • I wear my ignorance openly, excel is not my chosen career, its a means to an ends
    • Posting Guidelines Want to post well laid out questions and answers Translate Excel Versions
      Code:
      [CODE ]Put Your Code[/ CODE]
    • Settings > General Settings (on the left) scroll to the bottom, > Miscellaneous Options > Use ENHANCED
    • X-Posting Guidelines Rule 13 > CHART STUFF

  3. #3
    Board Regular
    Join Date
    Jul 2012
    Location
    Hampshire, UK
    Posts
    5,054
    Post Thanks / Like
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Hide Command Button

    Hi,

    try

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        
        If Not Intersect(Target, Me.Range("D8")) Is Nothing Then
            Me.CommandButton1.Visible = CBool(Target.Value > 0 And Target.Value < 5)
        End If
        
    End Sub
    Dave

  4. #4
    Board Regular
    Join Date
    Jul 2018
    Location
    Auckland
    Posts
    308
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Hide Command Button

    Thank you dmt32! That did the trick

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •