How do I make a command button invisible or visible?

G

Guest

I have two command buttons. One hides a range of columns with VB code. One
unhides the same range with VB code. Due to space constraints I would like to
have the 'hide" button set the visible property of that button to false and
the "hide button" to true and visa-versa with the other button. By placing
the buttons on top of each other the proper button is always visible and
space used is compact. I am new to VB and can't get this to work although I
assume it is possible. Suggestions?
 
G

Guest

hi,
no need to do that. you can combine the show/hide in one
button.
here is some code i use. it only hide 1 column at a time
but you can modify it to your needs. it also changes the
button color and captions so that i can use the button as
a header.(same more space)
Private Sub CommandButton1_Click()
' hide/show column
If Columns("L:L").Hidden = True Then
Columns("K:K").Hidden = True
Columns("L:L").Hidden = False
CommandButton1.Caption = "inches"
CommandButton1.BackColor = &HFF&
Else
Columns("K:K").Hidden = False
Columns("L:L").Hidden = True
CommandButton1.Caption = "cms"
CommandButton1.BackColor = &HC000&
End If
End Sub
 
G

Guest

Here is some code to just change the caption on the button. Generally a
better way to go. This assumes that the button that you got came off of the
control toolbox, and you go into properties of that button and change the
Name to cmdHide.

Private Sub cmdHide_Click()
If ActiveSheet.Range("A11:A14").EntireRow.Hidden = False Then
ActiveSheet.Range("A11:A14").EntireRow.Hidden = True
ActiveSheet.cmdHide.Caption = "Unhide"
Else
ActiveSheet.Range("A11:A14").EntireRow.Hidden = False
ActiveSheet.cmdHide.Caption = "Hide"
End If

End Sub

HTH
 
B

Bob Phillips

Private Sub cmdHide_Click()
With Me
.cmdHide.Visible = False
.cmdUnhide.Visible = True
.cmdDo1.Visible = False
End With
End Sub


Private Sub cmdUnhide_Click()
With Me
.cmdHide.Visible = True
.cmdUnhide.Visible = False
.cmdDo1.Visible = True
End With
End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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