Hide Command Button

tlc53

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

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top