View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.misc
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Selecting sheet with VB

Hi,

If you confident you have sheets as named then i'm confused but with regard to

Sheets("SheetNames").Range("d2").Value


That won't work because it will look for a worksheet '"Sheetnames" but this
will provided 'Sheet60' is a valid sheet name and the value in D2 is a valid
sheet name

Sheets(Sheets("Sheet60").Range("d2").Value).Select

Mike

"RobN" wrote:

Fraid I do!

I copied and pasted it here from the VBA projects window --- Sheet60. It's
full name is Sheet60 (SheetNames).
However, I did try amending your Sheets("Sheet60").Range("d2").Value
to
Sheets("SheetNames").Range("d2").Value, but that didn't work either.

I'm also a bit confused with the command Sheet or Sheets. Which one should
it be?

Rob

"Mike H" wrote in message
...
Hi,

Then you don't have a Sheet60 or you don't have a sheet that matches what
you have typed in D2 of Sheet60. Check for spelling and spaces.

Mike

"RobN" wrote:

Mike,

Now says Subscript out of range.

Rob

"Mike H" wrote in message
...
Try,

Dim ss As String
ss = Sheets("Sheet60").Range("d2").Value
Sheets(ss).Select

Mike

"RobN" wrote:

(I posted this in the office.misc newsgroup by mistake)

I've used the following to try and have VB select a sheet dependant on
the
value in d2.
Dim ss As Variant
Set ss = Sheet60.Range("d2")

How do I apply that now to select that sheet? I thought something
like
sheet(ss).select would do it, but it doesn't work

Sheets(ss).select does work, but doesn't go to the correct sheet
number,
whereas Sheet(ss) brings up a "Sub or Function not defined" error.

Rob