+ Reply to Thread
Results 1 to 4 of 4

setting sheet as variable

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    setting sheet as variable

    Hello,

    I need to create sheets, and after creating I need a few things to do with them, and I also want to name them.
    I have added a variable, nSheet, and I want to use it for the last sheet I created, somehow like this:

    dim nSheet as worksheet
    for i=lbound(myArray) to ubound(myArray)
        set nsheet=sheets.add after:=sheets(sheets.count) name=myArray(i)
        with nsheet
         .
         .
         end with
    next
    Unfortunately I cannot figure out, how this line
    set nsheet=sheets.add after:=sheets(sheets.count) name=myArray(i)
    should look like, maybe it cannot be done in one line.
    Could anybody help?

    Many Thanks

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: setting sheet as variable

    Hi
    try two lines:

    Set nsheet = Sheets.Add(after:=Sheets(Sheets.Count))
    nsheet.Name = myArray(i)

  3. #3
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: setting sheet as variable

    Thanks, you are right, I have confused myself with the syntax.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: setting sheet as variable

    why do it in one line?
    dim nSheet as worksheet
    for i=lbound(myArray) to ubound(myArray)
        set nsheet=sheets.add after:=sheets(sheets.count)
        with nsheet
         .name=myArray(i)
         .
         end with
    next
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ 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