View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
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