Solved

Define a Sheets Array dynamically

Posted on 2014-11-04
4
57 Views
Last Modified: 2014-11-05
How can I define this array dynamically?

Sheets(Array("AAL Wk 40", "ACA Wk 40", "AFR Wk 40", "BAW Wk 40", "BWA Wk 40", _
        "ETD Wk 40", "GIA Wk 40", "LAN Wk 40", "LOT Wk 40", "OAS Wk 40", "RJA Wk 40", _
        "SVA Wk 40", "TAR Wk 40")).Copy

The optimum solution would be something like this:
Sheets(Array(Sheets(1) through Sheets(Sheets.Count - 1)).copy  - OR -  
Sheets(Array(Sheets(1).Name & ":" & Sheets(Sheets.Count - 1).Name).copy

Do you know what I mean?

Thanks,
John
0
Comment
Question by:gabrielPennyback
4 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40423139
Is there anything unique about the sheets that you want to include in the array? Also what do you want to do with the array?
0
 
LVL 33

Assisted Solution

by:Norie
Norie earned 100 total points
ID: 40423150
Perhaps something like this.
Dim arrSheets()
Dim I As Long

    For I = 1 To Sheets.Count - 1
        ReDim Preserve arrSheets(1 To I)
        
         arrSheets(I) = Sheets(I).Name
    Next I
    
   Sheets(arrSheets).Copy

Open in new window

0
 
LVL 18

Accepted Solution

by:
krishnakrkc earned 400 total points
ID: 40423424
Sheets(Application.Transpose(Evaluate("Row(1:" & Sheets.Count - 1 & ")"))).Copy

Open in new window


Kris
0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 40424619
Thanks, Kris. Nothing gratifies me VBA-wise like a compact code, and you can't beat one line! inmorie, yours also works quite well, but I have to give Kris the bulk of the points because of the one line thing. :- )

Thanks to both of you,

John
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now