You can use
CommandButton1.Visible = False
If you don't want this to appear/not appear on loading your form you should
do something like this:
Sub Userform_Initialize
If range("A1").value = "N" then
CommandButton1.Visible = False
end if
End Sub
Hello Doug,
If your button is on a Worksheet then you will need a second macro to
check the cell's value and change the button's Visible property. This
second macro will need to run during the Worksheet_Activate() event,
and the Worksheet_Change() event. The code for both types of buttons
is provided. You may need to change the cell address that is checked,
and the button's name (only if it is different, and is a Control
Toolbox type).
'Second macro code. Place this in a Standard VBA Module
' Use this code if the Button is from the FORMS Toolbar
Public Sub HideUnhideButton()
With ActiveSheet
If .Range("A1") = "Y" Then
.DropDowns(Application.Caller).Visible = True
Else
.DropDowns(Application.Caller).Visible = False
End If
End With
End Sub
' Use this code if the Button is from the CONTROL TOOLBOX
Public Sub HideUnhideButton()
Dim Btn As MSForms.CommandButton
With ActiveSheet
Set Btn = .OLEObjects("CommandButton1").Object 'Change
the name of the Command button if needed
If .Range("A1") = "Y" Then
Btn.Visible = True
Else
Btn.Vsible = False
End If
End With
End Sub
'Event Code Procedures
Private Sub Worksheet_Change(BYVal Target As Range)
If Target.Address = "$A$1" Then Call HideUnhideButton
End Sub
Private Sub Worksheet_Activate()
Call HidenHideButton
End Sub
Sincerely,
Leith Ross