![]() |
Using Command Button to Hide Columns in another worksheet
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... |
Using Command Button to Hide Columns in another worksheet
You could change your code to...
Sheets("Sheet1").Columns("H:H").EntireColumn.Hidde n = 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" 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... |
Using Command Button to Hide Columns in another worksheet
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. Jim Cone wrote: You could change your code to... Sheets("Sheet1").Columns("H:H").EntireColumn.Hidde n = 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" 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... |
All times are GMT +1. The time now is 01:47 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com