Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 67
Default I can't select a range in VBA

I am trying to unhide some columns. I keep getting a "Select method of range
class failed" error. With "Columns("F:L").Select highlighted.

I am using Excel 2003.

I can record the action in a macro and it works, but then copying from the
macro to the button it doesn't work.

I would truly appreciate any help anyone can give me.


Private Sub CommandButton3_Click()

Sheets("Complete Frac Price Book").Visible = True
Sheets("Complete Frac Price Book").Select

Columns("F:L").Select
Selection.EntireColumn.Hidden = False
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default I can't select a range in VBA

hi
i'm not getting an error on my 2003 with your code.
try this with no select.....
Columns("F:L").EntireColumn.Hidden = False

just to see what happens

regards
FSt1

"bigjim" wrote:

I am trying to unhide some columns. I keep getting a "Select method of range
class failed" error. With "Columns("F:L").Select highlighted.

I am using Excel 2003.

I can record the action in a macro and it works, but then copying from the
macro to the button it doesn't work.

I would truly appreciate any help anyone can give me.


Private Sub CommandButton3_Click()

Sheets("Complete Frac Price Book").Visible = True
Sheets("Complete Frac Price Book").Select

Columns("F:L").Select
Selection.EntireColumn.Hidden = False

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,290
Default I can't select a range in VBA


Private Sub CommandButton3_Click()
Sheets("Complete Frac Price Book").Visible = True
Sheets("Complete Frac Price Book").Columns("F:L").Hidden = False
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"bigjim"
wrote in message
I am trying to unhide some columns. I keep getting a "Select method of range
class failed" error. With "Columns("F:L").Select highlighted.
I am using Excel 2003.
I can record the action in a macro and it works, but then copying from the
macro to the button it doesn't work.
I would truly appreciate any help anyone can give me.

Private Sub CommandButton3_Click()

Sheets("Complete Frac Price Book").Visible = True
Sheets("Complete Frac Price Book").Select

Columns("F:L").Select
Selection.EntireColumn.Hidden = False
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 67
Default I can't select a range in VBA

That worked. Thanks a bunch. I don't know why it works with a recorded
macro, but not when I'm writing the code for a button. Anyway, thanks again.
I really appreciate it.

"bigjim" wrote:

I am trying to unhide some columns. I keep getting a "Select method of range
class failed" error. With "Columns("F:L").Select highlighted.

I am using Excel 2003.

I can record the action in a macro and it works, but then copying from the
macro to the button it doesn't work.

I would truly appreciate any help anyone can give me.


Private Sub CommandButton3_Click()

Sheets("Complete Frac Price Book").Visible = True
Sheets("Complete Frac Price Book").Select

Columns("F:L").Select
Selection.EntireColumn.Hidden = False

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default I can't select a range in VBA

Jim's code is much better because he doesn't select the range to work with it.

But if you really wanted...

Private Sub CommandButton3_Click()

Sheets("Complete Frac Price Book").Visible = True
Sheets("Complete Frac Price Book").Select
Sheets("Complete Frac Price Book").Columns("F:L").Select
Selection.EntireColumn.Hidden = False
....


The unqualified range (Columns("F:L") refer to the activesheet in a General
module. But because this is in the worksheet (behind a commandbutton), the
unqalified range will refer to the sheet that owns the code.

And since you can only select a range on a worksheet that's active, it blows
up. (You activated "complete frac price book" and tried to select F:L on the
sheet with the code.)

But don't use my suggestion. Use Jim's.

bigjim wrote:

I am trying to unhide some columns. I keep getting a "Select method of range
class failed" error. With "Columns("F:L").Select highlighted.

I am using Excel 2003.

I can record the action in a macro and it works, but then copying from the
macro to the button it doesn't work.

I would truly appreciate any help anyone can give me.

Private Sub CommandButton3_Click()

Sheets("Complete Frac Price Book").Visible = True
Sheets("Complete Frac Price Book").Select

Columns("F:L").Select
Selection.EntireColumn.Hidden = False


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
When entering data into a range of cells, select the entire range. Q Excel Discussion (Misc queries) 0 September 26th 07 04:36 AM
Select a range [email protected] Excel Discussion (Misc queries) 1 March 22nd 07 10:16 AM
Select Using Range vijaya Excel Discussion (Misc queries) 1 November 2nd 05 07:33 PM
I cannot select a range Kassie Excel Discussion (Misc queries) 3 February 21st 05 06:09 AM
Select a range Kevin Excel Discussion (Misc queries) 3 February 18th 05 11:04 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"