Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I protect an object in worksheets? | Excel Discussion (Misc queries) | |||
How do i assign the ActiveWorkbook.Worksheets to a worksheets object? | Excel Worksheet Functions | |||
method Worksheets of object _Global failed | Excel Programming | |||
Different Behaviour of Public Object Vars in Worksheets vs. Add-In | Excel Programming | |||
How do I create a Worksheets object | Excel Programming |