Hide button based on a cell value

  • Thread starter Johanna Gronlund
  • Start date
J

Johanna Gronlund

Hello,

I have been trying to write a macro that would hide a button based on a cell
value (cell N20). Somehow, it doesn't work. If N20=1, the button should be
visible. If not, then it should be hidden.

The button is called Button 4388 and the sheet is called Results.

This is what I have come up with so far but as I said it doesn't work
(please don't laught, I'm a beginner!):

Sub HideButton()

Dim myButton As Button

With ActiveSheet
Set myButton = .Buttons("Button 4388")
If Range("N20").Value = "1" Then
..Visible = True
Else
..Visible = False
End If
End With

End Sub
 
O

ozgrid.com

It depends on what type of "Button" you mean?

Try;

Sub HideButton()

Dim myButton As Shape

With ActiveSheet
Set myButton = .Shape("Button 4388")
myButton.Visible = .Range("N20") = 1
End With

End Sub
 
J

Johanna Gronlund

Thanks for a quick reply.

It's a button from the form's control menu.

I tried the code but there is an error message which it highlights this row:
Set myButton = .Shape("Button 4388")

The error message is:
Run-time error '438'
Object doesn't support this property or method.

Johanna
 
B

Bob Phillips

Try this

Sub HideButton()
Dim myButton As Button

With ActiveSheet
Set myButton = .Buttons("Button 4388")
myButton.Visible = .Range("N20").Value = 1
End With

End Sub



--

HTH

Bob

Johanna Gronlund said:
Thanks for a quick reply.

It's a button from the form's control menu.

I tried the code but there is an error message which it highlights this
row:
Set myButton = .Shape("Button 4388")

The error message is:
Run-time error '438'
Object doesn't support this property or method.

Johanna
 
J

Johanna Gronlund

Thanks very much, that worked!!!

--
Johanna


Bob Phillips said:
Try this

Sub HideButton()
Dim myButton As Button

With ActiveSheet
Set myButton = .Buttons("Button 4388")
myButton.Visible = .Range("N20").Value = 1
End With

End Sub



--

HTH

Bob




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top