Buttons Embedded in a Worksheet

W

Wendy

OK - I know - This is probably a basic questions for you experts, but I would
like to know how to add buttons to a worksheet that hide and unhide specific
colums, and how these commands/buttons are created.

I have inherited a workbook that someone else created, and now I need to add
more data to it in the same manner as the original author.
 
J

Jim Thomlinson

Bring up the Control Toolbox toolbar (Tools -> Customize -> Toolbars ->
Control Toolbox). Click on the Button icon and then click on the worksheet to
place one on your sheet. Right click the button and select Properties. Change
the Caption to something like Hide/Unhide. Double click on the button. This
will take you to the code window. Add something like the following the the
code that was added for you...

Private Sub CommandButton1_Click()
Columns("B:C").Hidden = Not Columns("B:C").Hidden
End Sub
 
W

Wendy

Thanks Jim -
I have the button, and I pasted your code.
Now what? How do I save it, and make it work?
 
J

Jim Thomlinson

You are probably still in design mode. There is a little triangle / ruler
icon on the Control Toolbox toolbar. Click it to exit design mode. You should
now be able to click the button to hide or unhide the columns...
 

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