Using Command Button to Hide Columns in another worksheet

A

AndrewJ

Hello All,

I created what I thought was a really simple workbook, but have run
across a macro error that I can't seem to solve. Probably really simple
for some, but has stumped me on working any further on the workbook:

I recorded a macro to hide a column on a specific worksheet (code
below):

Sheets("Sheet1").Select
Columns("H:H").Select
Selection.EntireColumn.Hidden = True

However, when I copied the code to a command button on another
worksheet I get:

"Run-time error '1004':

Select method of Range class failed"

The macro works fine when I run it through the menu, however it will
not work with the command button. When I click on the Debug, it
highlights the "Columns("H:H").Select"

Any insight will be appreciated...
 
J

Jim Cone

You could change your code to...
Sheets("Sheet1").Columns("H:H").EntireColumn.Hidden = True
(no selection is done)
-or-
If you are using buttons from the Control Toolbox try ...
Changing the TakeFocusOnClick property of the button to False.

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"AndrewJ"
<[email protected]>
wrote in message
Hello All,
I created what I thought was a really simple workbook, but have run
across a macro error that I can't seem to solve. Probably really simple
for some, but has stumped me on working any further on the workbook:
I recorded a macro to hide a column on a specific worksheet (code
below):

Sheets("Sheet1").Select
Columns("H:H").Select
Selection.EntireColumn.Hidden = True

However, when I copied the code to a command button on another
worksheet I get:

"Run-time error '1004':

Select method of Range class failed"

The macro works fine when I run it through the menu, however it will
not work with the command button. When I click on the Debug, it
highlights the "Columns("H:H").Select"
Any insight will be appreciated...
 
A

AndrewJ

Thanks alot Jim,

I previously tried chaning the TakeFocusOnClick property before
posting, but with no luck, but changing my code so that no selecting is
required worked perfectly. Thanks again.
 

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