Cell = "YES" then CommandButton2 Visible

C

cru

Any assistance is appreciated!

I need a code which will make the commandbutton2 visible if cell "d18" is YES.

Any ideas?
 
K

Kevin B

Press Alt + F11 to open the Visual Basic Editor. In the project window,
under MICROSOFT EXCEL OBJECTS double click the workseet that has the command
buttons.

In the worksheet module add the following event code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Range("D18").Value = "Yes" Then
Me.CommandButton2.Visible = True
Else
Me.CommandButton2.Visible = False
End If

End Sub
 
C

cru

Hi Kevin,

Thank you so much!

Cru

Kevin B said:
Press Alt + F11 to open the Visual Basic Editor. In the project window,
under MICROSOFT EXCEL OBJECTS double click the workseet that has the command
buttons.

In the worksheet module add the following event code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Range("D18").Value = "Yes" Then
Me.CommandButton2.Visible = True
Else
Me.CommandButton2.Visible = False
End If

End Sub
 
M

Mike

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$18" Then
If UCase(Target.Value) = "YES" Then
CommandButton2.Visible = True
else
CommandButton2.Visible = false
End If
End If
End Sub
 
R

Rick Rothstein

A shorter routine...

Private Sub Worksheet_Change(ByVal Target As Range)
CommandButton1.Visible = (Range("D18").Value = "YES")
End Sub

Note that the above is case-sensitive; here is a non-case-sensitive
routine...

Private Sub Worksheet_Change(ByVal Target As Range)
CommandButton1.Visible = (UCase(Range("D18").Value) = "YES")
End Sub
 
C

cru

I originally used the following code use macro (excluding if condition):

Sub Print_Preview_InputForm12()
'
' Print_Preview Macro
'
Dim Answer As String
Sheets("Ltr1").Visible = True
Sheets("Ltr1").Select
Range("A1:K48").Select
ActiveSheet.PageSetup.PrintArea = Selection.Address
ActiveSheet.PrintPreview
Sheets("Print Ctr").Select

End Sub

Is there a way to insert the code into the above code so that if "d18" =
"yes" the button will be visible?

Thanks,
cru
 
R

Rick Rothstein

Just add this line to your macro...

CommandButton2.Visible = (Range("D18").Value = "YES"
 
R

Rick Rothstein

I really should have filtered the change event. For the case-sensitive
version...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$18" Then
CommandButton1.Visible = (Target.Value = "YES")
End If
End Sub

For the non-case-sensitive version...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$18" Then
CommandButton1.Visible = (UCase(Target.Value) = "YES")
End If
End Sub
 
C

cru

Rick,

How can I incorporate the code you have to the following code:

Sub Print_Preview_InputForm12()
'
' Print_Preview Macro
'
Dim Answer As String
Sheets("Ltr1").Visible = True
Sheets("Ltr1").Select
Range("A1:K48").Select
ActiveSheet.PageSetup.PrintArea = Selection.Address
ActiveSheet.PrintPreview
Sheets("Print Ctr").Select

End Sub

I currently have this but if I can incorporate your code into the above code
then I wanted to see if I can eliminate from creating commandbutton. Thanks.

cru
 
R

Rick Rothstein

Just add this line to your macro...

CommandButton2.Visible = (Range("D18").Value = "YES")
 
C

cru

Sorry Mike...

My goal is to have the command button to fire off the following sequence.
1. If D18 = Yes;
2. Button be visible for Print Preview
3. Upon pressing the button
2. Open hidden Ltr1 tab
3. Preview Ltr1 tab
4. If D18 = No;
3. Button be hidden

I apologize for the vague question and I do appreciate your help. Thanks.
cru
 
Top