Reputation: 539
I'd like to create some VBA code that will hide a command button based on a cell's value.
If cell "S17"= "(All)" then the command button should be hidden, otherwise it can remain visible.
As I stated, the value in cell S17 changes dynamically, so the code will need to update whenever the user makes a change.
Here is my code so far:
Private Sub Worksheet_Change(ByVal Target As Range)
If Sheet3.Range("S17").Value = "(All)" Then
CommandButton6.Visible = False
Else
CommandButton6.Visible = True
End If
End Sub
Currently this isn't doing anything. If cell S17 = "(All)" the command button is still visible.
Upvotes: 0
Views: 6586
Reputation: 434
Here is your code -
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("S17") Then
If Target.Value = "(All)" Then
CommandButton6.Visible = False
Else
CommandButton6.Visible = True
End If
End If
End Sub
Upvotes: 1