+ Reply to Thread
Results 1 to 3 of 3

Add new worksheet and assign it to an object variable?

Hybrid View

  1. #1
    Thief_
    Guest

    Add new worksheet and assign it to an object variable?

    I want to copy a worksheet and place it after an existing worksheet, then
    assign the new worksheet to an object variable but can't get my head around
    the code today. Here is what I have so far:

    Set NewWS =
    Worksheets(BackupWS).Copy(After:=Sheets("Summary"))
    NewWS.Name = ws.Name

    The above is obviously flawed as it doesn't work for me.

    XL2002 SP2
    Win2K Pro


    --
    |
    +--Thief_
    |




  2. #2
    OJ
    Guest

    Re: Add new worksheet and assign it to an object variable?

    Hi,
    try this....

    Worksheets(BackupWS).Copy , Sheets("Summary")
    Set NewWS = Activesheet

    Hth
    OJ


  3. #3
    Patrick Molloy
    Guest

    RE: Add new worksheet and assign it to an object variable?

    Dim WS As Worksheet
    Set WS = Worksheets.Add(After:=Worksheets(Worksheets.Count))

    With WS
    .Name = "MynewSheet"
    ''' more such stuff, eg
    With .Range("C6: K20")
    .Interior.colorindex = 34
    End With

    End With


    Patrick Molloy
    Microsoft Excel MVP


    "Thief_" wrote:

    > I want to copy a worksheet and place it after an existing worksheet, then
    > assign the new worksheet to an object variable but can't get my head around
    > the code today. Here is what I have so far:
    >
    > Set NewWS =
    > Worksheets(BackupWS).Copy(After:=Sheets("Summary"))
    > NewWS.Name = ws.Name
    >
    > The above is obviously flawed as it doesn't work for me.
    >
    > XL2002 SP2
    > Win2K Pro
    >
    >
    > --
    > |
    > +--Thief_
    > |
    >
    >
    >
    >


+ 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