+ Reply to Thread
Results 1 to 4 of 4

Move array of worksheets into another workbook

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Move array of worksheets into another workbook

    Hi Guys,

    i want to select 3 dynamic worksheets names into another workbook:

    So something like:

        Sheets(Array("Customer", "Development")).Select
        Sheets(Array("Customer", "Development")).move
    but in "Customer" and "Development" i can have dynamic changed variable.
    So worksheets can have different names.

    How can i pass worksheet variables into this method?
    I didnt found solution in web...

    Please help,
    Jacek

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,593

    Re: Move array of worksheets into another workbook

    If you know sheet index of the worksheets then
    Sheets(Array(1,2,3)).Move
    will move left 3 worksheets.

    Or simply use array variable like
    Dim wsArray
    wsArray=Array("Blabl1","Blabla2","etc")
    Sheets(myArray).Move

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Move array of worksheets into another workbook

    You can use standard array of strings to do that.
    And any array element can be directly filled with sheet-to-be-moved name, like (just illustrative, simplest case):
    Dim arr(1 To 3) As String
    arr(1) = "Arkusz1"
    arr(2) = "Arkusz2"
    arr(3) = "Arkusz3"
    Sheets(arr).Move
    but of course you can first
    Dim arr() As String, sheetstobemoved as long
    redim arr(1 to 1)
    and then dynamically grow the array
    if someconditionformoving then
      sheetstobemoved = sheetstobemoved +1
      redim preserve arr(1 to sheetstobemoved) 
      arr(sheetstobemoved) = activesheet.name
    end if
    and finally, once the whole arr is ready move all "collectred" sheets:
    Sheets(arr).Move
    Best Regards,

    Kaper

  4. #4
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Move array of worksheets into another workbook

    Thank you Guys,

    very helpful.

    Jacek

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] move all visible worksheets in a workbook all into new single workbook
    By Pi* in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-13-2016, 03:04 PM
  2. move visible of worksheets in a workbook all into new workbook
    By Pi* in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-12-2016, 08:55 PM
  3. Replies: 1
    Last Post: 02-12-2016, 08:09 PM
  4. [SOLVED] VBA code to create a workbook and copy or move worksheets in to workbook through loop
    By anishkumarvs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-16-2015, 05:40 AM
  5. How to move several worksheets in one workbook to several different workbooks
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-07-2010, 03:50 PM
  6. Move WorkSheets Within Same WorkBook!!
    By James Cooper in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2006, 12:10 AM
  7. Move worksheets to a new workbook
    By mrdata in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-05-2006, 05:35 PM

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