iKKi
12/18/2006 8:53:00 PM
That's because you didn't declare from which sheet range("A1) you took the
data from,so the correct answer would be;
'In a new workbook
Private Sub Test()
Dim Name As String
Name = Worksheets("sheet1").Range("A1").Value
Sheets(Name).Select
End Sub
<yonathan.sabbah@gmail.com> wrote in message
news:1166471482.421353.121990@73g2000cwn.googlegroups.com...
> Thanks all for your answers,
>
> If I create a new book, put "Sheet2" on A1 and add your code I get the
> following:
>
> Run time error 9
> Subscript out of range
>
> I don't know why this works on your excel and not mine (XL 2003 too!).
>
> Regards,
>
> Yona
>
>
> Gord Dibben wrote:
>> Yona
>>
>> This works for me........xl2003
>>
>> Dim Name As String
>> Name = Range("A1").Value
>> Sheets(Name).Select
>>
>> Note the Sheets as opposed to Sheet
>>
>>
>> Gord Dibben MS Excel MVP
>>
>>
>> On 18 Dec 2006 11:09:15 -0800, yonathan.sabbah@gmail.com wrote:
>>
>> >Hello,
>> >
>> >Ok we all know that I can select a sheet on Excel by doing:
>> >sheets("Name").select or worksheets("Name").select
>> >
>> >But my problem is that I take the name from a cell with something like:
>> >
>> >Dim Name as String
>> >Name = Range("A1").value
>> >
>> >If I now do:
>> >sheet(Name).select
>> >
>> >I get an error (Name as to be an Object, not a string). I can I do
>> >this? It shouldn't be that hard to select a sheet from a cell value!
>> >
>> >Damm VBA!
>> >
>> >Regards,
>> >
>> >Yona
>