+ Reply to Thread
Results 1 to 6 of 6

Worksheets() Object

  1. #1
    dallin
    Guest

    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. #2
    Dave Peterson
    Guest

    Re: 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. #3
    dallin
    Guest

    Re: 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. #4
    Tim Williams
    Guest

    Re: 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" <[email protected]> wrote in message news:[email protected]...
    > 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. #5
    Dave Peterson
    Guest

    Re: 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. #6
    dallin
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1