ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code Help (https://www.excelbanter.com/excel-programming/405809-code-help.html)

Scott Halper

Code Help
 
I have the code below and I keep getting this error meesage, "Select
Method of Range Class failed". I am trying to just side some column
when a user clicks a button.


Private Sub FirstChooser_Click()
Application.ScreenUpdating = False
Sheets("Model").Select
Columns("P:Q").Select
Selection.EntireColumn.Hidden = True
Columns("S:T").Select
Selection.EntireColumn.Hidden = True
Range("O56").Select
Application.ScreenUpdating = True
End Sub

Thanks for the help.

Scott

John

Code Help
 
try following (not tested)

Private Sub FirstChooser_Click()
Application.ScreenUpdating = False
With Worksheets("Model")
.Activate
.Columns("P:Q").EntireColumn.Hidden = True
.Columns("S:T").EntireColumn.Hidden = True
.Range("O56").Select
End With
Application.ScreenUpdating = True
End Sub


--
JB


"Scott Halper" wrote:

I have the code below and I keep getting this error meesage, "Select
Method of Range Class failed". I am trying to just side some column
when a user clicks a button.


Private Sub FirstChooser_Click()
Application.ScreenUpdating = False
Sheets("Model").Select
Columns("P:Q").Select
Selection.EntireColumn.Hidden = True
Columns("S:T").Select
Selection.EntireColumn.Hidden = True
Range("O56").Select
Application.ScreenUpdating = True
End Sub

Thanks for the help.

Scott


Bob Flanagan[_2_]

Code Help
 
Your code works fine for me. Are you in the workbook containing sheets
"model"? Do you have a chart selected by any chance? Which line is failing?
What version of Excel are you using? There was a problem quite a while ago
with the button taking the focus. Try adding the line "selection.activate"
as the first line.

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel

"Scott Halper" wrote in message
...
I have the code below and I keep getting this error meesage, "Select
Method of Range Class failed". I am trying to just side some column
when a user clicks a button.


Private Sub FirstChooser_Click()
Application.ScreenUpdating = False
Sheets("Model").Select
Columns("P:Q").Select
Selection.EntireColumn.Hidden = True
Columns("S:T").Select
Selection.EntireColumn.Hidden = True
Range("O56").Select
Application.ScreenUpdating = True
End Sub

Thanks for the help.

Scott





All times are GMT +1. The time now is 10:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com