How to select multiple sheets using macro

Hi,

I want to select multiple sheets using macro in the 
runtime.
I tried recording the action and it gave the following 
code:
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select

Actually i want to copy all the sheets in the current 
workbook and move it to a new workbook..

Hence the next line would be:
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).copy..

which would copy the selected sheets to a new workbook..

Now the problem is, the sheet names mentioned in the code 
are fixed,, whereas i want to select the sheets 
dynamically in the runtime..since the sheet names could be 
changed in future..

I have tried running a loop to get all the sheet names and 
put it in Array function, which didn't work at all..

Does anyone know how to modify this code to select sheets 
dynamically 

or 

any other solution to do the same.

Any help would be highly appreciated.

Regards
Sri
0
anonymous (74717)
11/5/2004 5:12:41 PM
excel.misc 78881 articles. 5 followers. Follow

3 Replies
558 Views

Similar Articles

[PageSpeed] 9

"Sri" <anonymous@discussions.microsoft.com> schreef in bericht
news:044f01c4c35a$a8c19b70$a501280a@phx.gbl...
> Hi,
>
> I want to select multiple sheets using macro in the
> runtime.
> I tried recording the action and it gave the following
> code:
> Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
>
> Actually i want to copy all the sheets in the current
> workbook and move it to a new workbook..
>
> Hence the next line would be:
> Sheets(Array("Sheet1", "Sheet2", "Sheet3")).copy..
>
> which would copy the selected sheets to a new workbook..
>
> Now the problem is, the sheet names mentioned in the code
> are fixed,, whereas i want to select the sheets
> dynamically in the runtime..since the sheet names could be
> changed in future..
>
> I have tried running a loop to get all the sheet names and
> put it in Array function, which didn't work at all..
>
> Does anyone know how to modify this code to select sheets
> dynamically
>
> or
>
> any other solution to do the same.
>
> Any help would be highly appreciated.
>
> Regards
> Sri

You can cycle through your sheets collection using Sheets(1), Sheets(2),
etc.


0
tbot (20)
11/5/2004 5:52:04 PM
Sri,

If you want to copy the whole workbook, you can simply use

Activeworkbook.SaveCopyAs "New File Name.xls"

or use SaveAs if you want to simply continue working on the new workbook....

HTH,
Bernie
MS Excel MVP

"Sri" <anonymous@discussions.microsoft.com> wrote in message
news:044f01c4c35a$a8c19b70$a501280a@phx.gbl...
> Hi,
>
> I want to select multiple sheets using macro in the
> runtime.
> I tried recording the action and it gave the following
> code:
> Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
>
> Actually i want to copy all the sheets in the current
> workbook and move it to a new workbook..
>
> Hence the next line would be:
> Sheets(Array("Sheet1", "Sheet2", "Sheet3")).copy..
>
> which would copy the selected sheets to a new workbook..
>
> Now the problem is, the sheet names mentioned in the code
> are fixed,, whereas i want to select the sheets
> dynamically in the runtime..since the sheet names could be
> changed in future..
>
> I have tried running a loop to get all the sheet names and
> put it in Array function, which didn't work at all..
>
> Does anyone know how to modify this code to select sheets
> dynamically
>
> or
>
> any other solution to do the same.
>
> Any help would be highly appreciated.
>
> Regards
> Sri


0
Bernie
11/5/2004 6:06:22 PM
And one more:

sheets.copy

or even
worksheets.copy
(to avoid chartsheets and other non-worksheets)

Sri wrote:
> 
> Hi,
> 
> I want to select multiple sheets using macro in the
> runtime.
> I tried recording the action and it gave the following
> code:
> Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
> 
> Actually i want to copy all the sheets in the current
> workbook and move it to a new workbook..
> 
> Hence the next line would be:
> Sheets(Array("Sheet1", "Sheet2", "Sheet3")).copy..
> 
> which would copy the selected sheets to a new workbook..
> 
> Now the problem is, the sheet names mentioned in the code
> are fixed,, whereas i want to select the sheets
> dynamically in the runtime..since the sheet names could be
> changed in future..
> 
> I have tried running a loop to get all the sheet names and
> put it in Array function, which didn't work at all..
> 
> Does anyone know how to modify this code to select sheets
> dynamically
> 
> or
> 
> any other solution to do the same.
> 
> Any help would be highly appreciated.
> 
> Regards
> Sri

-- 

Dave Peterson
ec35720@netscape.com
0
ec357208423 (183)
11/5/2004 10:19:38 PM
Reply:

Similar Artilces:

how can I close a UserForm using a shortcut key ?
This is a multi-part message in MIME format. ------=_NextPart_000_0011_01C4D528.49737CD0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable How can I close a UserForm using a shortcut key ? T. I. A. ------=_NextPart_000_0011_01C4D528.49737CD0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1">...

Run report on multi selected records.
I try to make a report for a custom entity that works like the Account Summary: let's say that it's Customer's Inquiry Summary for entity Customer's Inquiry I made the report so that I'm able to run the report on Customer's Inquiry Form. But when I select multi records in the list of Customer's Inquiry and run report, only one record is show in one page of the the report. I would like to have the selected records appear in the report with each record on each page. How can I do this? ...

Combo box list selection based on earlier selection by user
HI, I have a form that has a combo box 1 (Product) that reads a the Product table and has a unique id attached to each product (RO#). There is a second combo box 2 that is RO#. Now what I would like to do is when a user selects a Product in combo box 1, the system should lookup the Product selected from combo box 1 and upload the corresponding RO# in the combo box 2 list. Now I am using both combo boxes as Unbound and in the combo box 2 I have the two columns Product and RO# - in the Criteria row of RO# I have the following: Like IIf([Forms]![xa_f_lookup]![RO#]=" ",[Forms]![x...

Searaching for Contacts with multiple categories
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC Using the search function, it seems I am not able to search for a contact that belongs to more than one category. It seems to only recognize the contacts primary category. Can this be true? <br> It makes searching for contacts by multiple characteristics (categories, used like keywords), not possible. Please tell me there is another way. To clarify, I am trying to find an item whose category is both A and B. I can of course search for A or B, even though they have other categories assigned to them ...

Can't select objects in Excel 2007
I'm trying to create a form in Excel 2007, and although I can manipulate, copy & paste controls (check boxes, etc) I can't select multiple objects to align them, etc. I've checked on-line help (and have followed the instructions), and other websites, but no one seems to have indicated a problem. It is extremely cumbersome and I need a solution. Any ideas? Thanks in advance, Jim Berglund I know this is about a year too late, but it may help others who have stumbled across this page looking for similar help. On the Home tab, in the Editing group, click Find & Select....

serialization when using reflexion
Hello, My application needs to serialize a class, which was generated with xsd.exe from a XSD. It was working .NET 1.1 and it is working with .NET 2.0 very well. Now I need my assembly to be a plugin, and to be called by reflexion, but I get this Exception: Exception.Message: "There was an error generating the XML document." Exception.InnerException.Message: "Unable to cast object of type 'NMI.STARTi.EDI.Ingram.OrderRequest' to type 'NMI.STARTi.EDI.Ingram.OrderRequest'." The method I'm calling is static (I tried non-static as well) and the class ...

Function to multiple ranges
Which function may be used with multiple ranges? Commonly used "lookups", "index" and "match" don't seem to work. Is there a trick in multiple ranges? Tomek Polak Some functions work, others don't. INDEX has a 4th argument that allows you to specify the area (which of the multiple ranges). The lookup and match functions require a single contiguous block of cells. On Wed, 29 Oct 2003 14:19:08 +0100, "Tomek" <tpolak@poczta.onet.pl> wrote: >Which function may be used with multiple ranges? > >Commonly used "lookups",...

Using SmartArt, how do you freeze the size/ position of boxes?
I'm creating a relationship tree using SmartArt and I have all the text in boxes. I'm trying to lay it out so it looks nice, but as I adjust the size and position of the boxes, it automatically adjusts the other boxes, and eventually the shifting ruins the adjusting I was trying to do. My text winds up scrunched and out of the place I intended it for. I've tried several times, starting from the top and bottom, by the time I get to the middle it's all out of whack. I adjusted the page size and should have plenty of room for it all to fit the way I need it to lo...

how do I use Microsoft Ooutlook with Yahoo Mail
I use Microsoft Outlook. How do I use Yahoo Mail with the M/O. I do all it says and I still cannot get it to work. Debby Townsend wrote: > I use Microsoft Outlook. How do I use Yahoo Mail with the M/O. I do > all it says and I still cannot get it to work. Unless you have a paid account , or use yahoo UK then you can't. Thank you Gordon. I live in Totola, British Virgin Islands so will need to go into Cable and Wireless to find out what the ISP address is. But how come you can use Outlook Express with an account like Hotmail? Thanks again Debby "Gordon" wrote: &g...

Lot Selection not Showing when I select PO on Receiving Entry
Usually, the Lot selection screen would pop up when I select a PO at the Line Detail of the Receivings Entry, now it does not! And GP will let items post without a lot number! It seems as if a setting has changed. Any ideas anyone? Any help is appreciated. Thanks, R Are you sure the item is marked to track lots? This wiould be set item by item on the Item Maintenance Options window. -- Richard L. Whaley Author / Consultant / MVP 2006-2008 Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com &q...

Select contact then hangs
Hi, please help. I have a user that when she selects a contact using To: in a new email, after selecting 2, it closes outlook??. Spec is W2kSP4\office2k with all windows updates and office updates installed. Profile has been deleted and re-created, plus i have set up personal folders and moved contacts into there, and set that folder as a default, but makes no difference. Please help. ...

Printing sheet to fit paper
I waste a lot of paper trying to print an Excel 2000 sheet on a piece of paper. I don't mind multiple vertical pages, but I can't stand multiple horizontal pages. Is there any trick I can use to find out if my document can fit so I don't waste paper? Print Preview. Howard Brazee wrote: > I waste a lot of paper trying to print an Excel 2000 sheet on a piece of paper. > > > I don't mind multiple vertical pages, but I can't stand multiple horizontal > pages. > > Is there any trick I can use to find out if my document can fit so I don't waste &...

Multiple Attributes
I have created a custom Entity - "Inventory" This has a relationship with Accounts which is used to show the location of a piece of hardware - a lookup field is used to choose an account. All good. However I'd also like to have a couple of other lookups for Supplier and Manufacturer. These are both stored in Accounts so they'd need to reference an entry in Accounts again. Is this possible? I know you cannot create multiple relationships between entities but can you create multiple attributes using the one relationship? Can anyone help with this - still got no further.....

How to use MSGP login to authenticate user?
Hi, i have a question and hope someone might be able to answer. i'm writing a program that using MSGP login to authenticate my users. As i know, MSGP store the encrypted password, my program was unable to match the username and password. Is there any way to decrypt the password? thanks. BC no "BC" <anonymous@discussions.microsoft.com> wrote in message news:53b301c49163$187c84e0$a501280a@phx.gbl... > Hi, i have a question and hope someone might be able to > answer. > i'm writing a program that using MSGP login to > authenticate my users. As i know, MSG...

Selecting rows from various sheets
Hi all, I have several sheets with a few columns in each. One colum in each sheet has a unique value. Most of these unique values are th same in each sheet but not all. Is there any way that I can set up new sheet that will have the unique value in column 1 and th corresponding column values frommeach sheet beside it. For example Sheet 1 aa 1 1 1 bb 2 2 2 cc 3 3 3 Sheet 2 aa 4 4 cc 5 5 Result aa 1 1 1 4 4 bb 2 2 2 cc 3 3 3 5 5 Thanks alot, Sha -- sha ----------------------------------------------------------------------- shav's Profile: http...

Add users to a Distribution Group using csv file
Is it possible? I have a list of approx 3200 users that I want to add to a common duistribution group w/o having to do it manually. At present I have a csv file with all the users that I want to be in the group. Is there a way to import them into the group using this file w/o recreating their accounts using csvde or ldife? TIA. Should be http://support.microsoft.com/?kbid=237677 http://www.computerperformance.co.uk/Logon/Logon_CSVDE_Bulk.htm Nue "kage13" <kage13@discussions.microsoft.com> wrote in message news:F8FB3846-DCDE-473F-9F1D-89E8CF0A66E3@microsoft.com... &...

Data from multiple sheets and workbooks
Each week I receive a workbook from one of my customers. It contains mutliple sheets with salesnumbers from all the branch of my customer. Each sheet contains from 1 000 to 15 000 lines of salesdata. Every article sold gets one line in the sheets. Each workbook are named "weeknr.xls" and are stored in the same folder. Now my question/problem. I need to gather all sales info for one branch on one article from all the weeks. I know how to get the data from one workbook to another, but how do I get it to scan all the workbooks in the folder. Any ideas. Dim oFSO Sub LoopFolder...

select text in Calendar
I'm working on a calendar in Publisher. I'm adding text into a cell by spacing down 1 point, then typing in 8 points. Doing fine until April. At that time, I can only select cells (whole days). It will not let me select the text. Help is no help. Any hints out there. Did I accidentally select something to do this? Bonnie Have you added a picture to the cell or a shape? If you have send it to the back, make the cell no fill and try again. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "GoBonnieGo" <GoB...

multiple V-lookup
I have a worksheet that has multiple rows that have the same name. For example. I have a worksheet that looks like this Name 401k FICA Julie 100 200 Patrick 200 400 Sam 50 100 Julie 100 200 Julie 100 200 Patrick 200 400 I am trying to figure out how I can have excel look at the worksheet and find all entries labed Patrick and return the columns already summed. Similar to a vlookup but able to know that if I want the 401k column it should return ...

macro to filter data based on selected data
Hi, I am looking for a macro that requests input of a reference code and then a date and then filters the data in my spreadsheet based on this criteria. I am using excel 2007. Any help with this will be greatly appreciated. You can probably record a macro while doing it manually and then clean it up and add input boxes to ask the question or input your variable in a cell and use that. If all else fails, If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the ...

look up on multiple sheets
i have a workbook made up of about 50 worksheets with same column headers but different row counts. In sheet one is a handfull of user names that could be found on any of the 50 sheets. how do i adjust this array so that it searches through all 50 sheets instead of the 3 columns currently identified in this formula? =MAX(IF((A$2:A$20212=D11)*(B$2:B$20212<=TODAY()),B$2:B$20212)) ...

Can I use automatic dialing in Outlook if I use a cable modem?
http://dts-l.org/goodpost.htm -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. "salsanstyx" <salsanstyx@discussions.microsoft.com> wrote in message news:85FF5912-B7DA-4E40-9AC6-943A3E9538CF@microsoft.com... | as long as you have a phone line connected to the computer, yes. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide) Need Help with Common Tas...

Auto Fill Macro Not Working Properly
Hi, I used a macro that I found through this newsgroup that auto fills down when you've got spaces in Column A that need filling with a prior value. It looks like this. Sub FillBlanksColumnA() Application.ScreenUpdating = False Extent = Cells.Rows.Count For i = 2 To Extent If Cells(i, 1) = "" Then Cells(i, 1) = Cells(i - 1, 1) Next i End Sub My problem is that this continues onto line 65000+. How can I revise this macro to stop when there is a blank or no value in Col B? Or can it be revised to say stop at line 2000? Thanks in advance. Jason Jason, If you want...

Link select with a blast
I have Win 7 Home Premium, x64. Quite often, when I select a link, a mouse pointer changes to a palm with a blast. I understand, the palm is the standard mouse pointer for link select, but what is the blast? What it indicates? -- Ilya Zeldes Fort Myers, Florida Hi Ilya, I suspect that this is being caused by a tracking program. Run something like Ad-Aware and see if it indicates a tracking company. If so, you can delete it, however, it might prevent you from accessing that particular website. Dave "Ilya Zeldes" wrote in message news:7A6FF9B1-5512-44...

Multiple excel sheets with same headings
I have 14 sheets with me for 14 different users. Now I want the data to come out of it for each person. The sheets are titled by the names of the individuals. Can MS Query be used for this? If yes, how? If not, then what shall I do? -- mohitmahajan ------------------------------------------------------------------------ mohitmahajan's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=8130 View this thread: http://www.excelforum.com/showthread.php?threadid=470132 ...