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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

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,925
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,778
Messages
5,488,804
Members
407,658
Latest member
Arias610

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top