Hide Command Button

tlc53

Active Member
Joined
Jul 26, 2018
Messages
365
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
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

mole999

Moderator
Joined
Oct 23, 2004
Messages
10,368
Office Version
2019, 2016, 2013
Platform
Windows
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
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
5,922
Office Version
2019
Platform
Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,102,471
Messages
5,487,082
Members
407,576
Latest member
Irene0

This Week's Hot Topics

Top