Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Worksheets() Object

I'm trying to pass a text variable to the Worksheets() object where Temp is a
text variable, however, I must not be using the right syntax. I've used
Worksheets("Temp") and Worksheets(Temp) without success. What is the correct
syntax for this?
--
thanks, mc
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Worksheets() Object

worksheets(Temp)
if Temp is a variable that holds a string.

But maybe you should test to see if that string actually contains a worksheet
name:

dim wks as worksheet
dim Temp as string

temp = "somestring"

set wks = nothing
on error resume next
set wks = worksheets(Temp)
on error goto 0

if wks is nothing then
'no worksheet with that name
else
'yes there is
end if



dallin wrote:

I'm trying to pass a text variable to the Worksheets() object where Temp is a
text variable, however, I must not be using the right syntax. I've used
Worksheets("Temp") and Worksheets(Temp) without success. What is the correct
syntax for this?
--
thanks, mc


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Worksheets() Object

Thanks - I'm still receiving a subscript out of range error -- any ideas?

Dim Temp As String
Dim Wks As Worksheet
Wks = Nothing
Temp = ActiveSheet.Range("B1").Value
Wks = Worksheets(Temp)


"Dave Peterson" wrote:

worksheets(Temp)
if Temp is a variable that holds a string.

But maybe you should test to see if that string actually contains a worksheet
name:

dim wks as worksheet
dim Temp as string

temp = "somestring"

set wks = nothing
on error resume next
set wks = worksheets(Temp)
on error goto 0

if wks is nothing then
'no worksheet with that name
else
'yes there is
end if



dallin wrote:

I'm trying to pass a text variable to the Worksheets() object where Temp is a
text variable, however, I must not be using the right syntax. I've used
Worksheets("Temp") and Worksheets(Temp) without success. What is the correct
syntax for this?
--
thanks, mc


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Worksheets() Object

The active workbook definitely has a sheet named with the value in B1 ?
Your error suggests there's a mis-match.

Tim


"dallin" wrote in message ...
Thanks - I'm still receiving a subscript out of range error -- any ideas?

Dim Temp As String
Dim Wks As Worksheet
Wks = Nothing
Temp = ActiveSheet.Range("B1").Value
Wks = Worksheets(Temp)


"Dave Peterson" wrote:

worksheets(Temp)
if Temp is a variable that holds a string.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Worksheets() Object

First, since wks represents an object (worksheet in this case), you'll want to
use:

set wks = nothing
and
set wks = worksheets(temp)

What do you have in B1?

And why did you lose the "on error" stuff?



dallin wrote:

Thanks - I'm still receiving a subscript out of range error -- any ideas?

Dim Temp As String
Dim Wks As Worksheet
Wks = Nothing
Temp = ActiveSheet.Range("B1").Value
Wks = Worksheets(Temp)

"Dave Peterson" wrote:

worksheets(Temp)
if Temp is a variable that holds a string.

But maybe you should test to see if that string actually contains a worksheet
name:

dim wks as worksheet
dim Temp as string

temp = "somestring"

set wks = nothing
on error resume next
set wks = worksheets(Temp)
on error goto 0

if wks is nothing then
'no worksheet with that name
else
'yes there is
end if



dallin wrote:

I'm trying to pass a text variable to the Worksheets() object where Temp is a
text variable, however, I must not be using the right syntax. I've used
Worksheets("Temp") and Worksheets(Temp) without success. What is the correct
syntax for this?
--
thanks, mc


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Worksheets() Object

Thank you everyone for your help. It works!!

"Dave Peterson" wrote:

First, since wks represents an object (worksheet in this case), you'll want to
use:

set wks = nothing
and
set wks = worksheets(temp)

What do you have in B1?

And why did you lose the "on error" stuff?



dallin wrote:

Thanks - I'm still receiving a subscript out of range error -- any ideas?

Dim Temp As String
Dim Wks As Worksheet
Wks = Nothing
Temp = ActiveSheet.Range("B1").Value
Wks = Worksheets(Temp)

"Dave Peterson" wrote:

worksheets(Temp)
if Temp is a variable that holds a string.

But maybe you should test to see if that string actually contains a worksheet
name:

dim wks as worksheet
dim Temp as string

temp = "somestring"

set wks = nothing
on error resume next
set wks = worksheets(Temp)
on error goto 0

if wks is nothing then
'no worksheet with that name
else
'yes there is
end if



dallin wrote:

I'm trying to pass a text variable to the Worksheets() object where Temp is a
text variable, however, I must not be using the right syntax. I've used
Worksheets("Temp") and Worksheets(Temp) without success. What is the correct
syntax for this?
--
thanks, mc

--

Dave Peterson


--

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
How do I protect an object in worksheets? beachbunny Excel Discussion (Misc queries) 2 May 29th 08 03:14 AM
How do i assign the ActiveWorkbook.Worksheets to a worksheets object? TS Excel Worksheet Functions 2 December 27th 06 02:49 PM
method Worksheets of object _Global failed ndalal Excel Programming 1 May 2nd 06 04:08 PM
Different Behaviour of Public Object Vars in Worksheets vs. Add-In Etienne Excel Programming 0 January 4th 06 02:13 PM
How do I create a Worksheets object Tony Lin Excel Programming 2 August 22nd 03 11:26 AM


All times are GMT +1. The time now is 09:46 AM.

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"