+ Reply to Thread
Results 1 to 14 of 14

Looping through unkown sheet names

  1. #1
    Registered User
    Join Date
    08-22-2012
    Location
    Townsville
    MS-Off Ver
    Excel 2010
    Posts
    38

    Looping through unkown sheet names

    Hi All,

    Searched and searched and couldn't find anything. Could you please help.

    I've got this code below which looks at my data and when data changes in the row it grabs it all and adds a new sheet and pastes the data. Problem I have now is I want to format each sheet (the same way) but I don't know the sheet names so can't reference them. Is there anyway I can loop through uknown names and perform a code?

    Please Login or Register  to view this content.
    I've tried this code but it only seems to do it on the first sheet - but does it at the count of the other sheets.

    Please Login or Register  to view this content.
    Any help greatly appreciated

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Looping through unkown sheet names

    Please Login or Register  to view this content.
    And if you want to exclude a particular sheet:

    Please Login or Register  to view this content.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    08-22-2012
    Location
    Townsville
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Looping through unkown sheet names

    Thanks for the reply daffodil - but it didn't work either, does the same as my other code. Just does it for the first sheet. At the moment I've got 9 different sheets and it does it 9 times on the first sheet.

    Any other thoughts?

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Looping through unkown sheet names

    Is your code on the sheet, or is it out in a Module?

    Also, in your code you call ActiveSheet a number of times which will only refer to the top active sheet.

  5. #5
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Looping through unkown sheet names

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-22-2012
    Location
    Townsville
    MS-Off Ver
    Excel 2010
    Posts
    38
    It is in a module. I will try that code when I get back in the office, thanks

  7. #7
    Registered User
    Join Date
    08-22-2012
    Location
    Townsville
    MS-Off Ver
    Excel 2010
    Posts
    38
    Also both the codes I use are in different subs, I use another to call them.

  8. #8
    Registered User
    Join Date
    08-22-2012
    Location
    Townsville
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Looping through unkown sheet names

    Sorry daffodil - pinkponies didn't work :P

    failed at this
    Please Login or Register  to view this content.
    I'm not having any problems with this part of the code though. Once this part finishes its all good, it's the next part when I call
    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Looping through unkown sheet names

    The bit that you have at the end of post #8 does not reference the worksheet(z) when selectin Range("A1:K1") so it will always reference the activesheet rather than looping through them. Try something like:
    Please Login or Register  to view this content.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Looping through unkown sheet names

    You need the dot before the Range i.e.

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Looping through unkown sheet names

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  12. #12
    Registered User
    Join Date
    08-22-2012
    Location
    Townsville
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Looping through unkown sheet names

    Thanks all for replying and helping me, I started at the bottom with Norie's and it worked a charm
    Cheers!!

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Looping through unkown sheet names

    Hey Amoxia,

    Did you try your own code with that one small change??

  14. #14
    Registered User
    Join Date
    08-22-2012
    Location
    Townsville
    MS-Off Ver
    Excel 2010
    Posts
    38
    Yes mate, and the . Before the rows to, also made some other changes, just more formatting really. Thanks

+ 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] Create an Array which has Sheet Names excluding a Few Sheet Names to be used in a MACRO
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-29-2013, 03:24 PM
  2. SUMIF with a list of unkown criteria
    By londbrit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2011, 05:57 PM
  3. Looping through object names
    By pdauction in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-22-2011, 05:01 AM
  4. looping over combobox names
    By lottesfog in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-23-2007, 01:35 AM
  5. Looping through range names
    By Craig in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-16-2005, 01:05 AM

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