• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

Excel Hide button based on condition

I added a button on my excel sheet and assigned a macro to it.

Is it possible to hide the button based on value on a particular cell.. like H1? If H1 contains "pass", only then the button should appear.

This is NOT a COMMAND Button. A simple Form button.
0
nainil
Asked:
nainil
  • 3
  • 2
  • 2
2 Solutions
 
hitsdoshi1Commented:
if H1="Pass" then
ActiveSheet.SHAPES("Button 1").visible=True
else
ActiveSheet.SHAPES("Button 1").visible=False
Endif

0
 
hitsdoshi1Commented:
Sorry.....you have to code like this:

If Range("H1")="Pass" Then
   ActiveSheet.SHAPES("Button 1").visible=True
Else
  ActiveSheet.SHAPES("Button 1").visible=False
Endif
0
 
jppintoCommented:
I've attached a sample file for you to test the code.

jppinto
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$H$1" Then
        If Target.Value = "pass" Then
            ActiveSheet.Shapes.Range(Array("Button 1")).Visible = True
        Else
            ActiveSheet.Shapes.Range(Array("Button 1")).Visible = False
        End If
    End If
End Sub

Open in new window

HideButton.xlsm
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nainilAuthor Commented:
@jppinto:
How is it supposed to work?

I tried adding the worksheet_change sub... saved the sheet, reopened the same.. the button existed whether or not the value exists in H1.

I opened the sheet you provided, and it works. But, not on my side.

@hitsdoshi1:

how / where do I need to add the code?
0
 
nainilAuthor Commented:
Never mind, I figured it out :)

Thank you.
0
 
jppintoCommented:
With all due respect, why did you accepted the solution from hitsdoshi1? If you use that code, you will get an error because it is missing the object sheet reference! The code is not completed and correct so you shouldn't accept that solution.

I would appreciate your comments on this please.

jppinto
0
 
jppintoCommented:
I would appreciate, for future reference, that you at least respond to my question!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now