+ Reply to Thread
Results 1 to 4 of 4

worksheets.add breaks Do loop in Excel 2010?

  1. #1
    Registered User
    Join Date
    02-12-2012
    Location
    Victoria
    MS-Off Ver
    Excel 2010, Excel 2013/64
    Posts
    23

    worksheets.add breaks Do loop in Excel 2010?

    Hi all,

    I have some old code that was written for Excel 2000, but I've since found a similar subroutine on MSDN which exhibits the same behaviour.

    Please Login or Register  to view this content.
    This code encapsulates the problem (the whole VBA is much longer).
    Column text headings are in A1 to n1 (i.e. dynamic range). Here a worksheet is added for each column header with the value of the header becoming the worksheet name.

    The issue is that the Sub routine exits (without error) when the first worksheets.add statement is reached, so the loop is only entered once.

    I've never seen this before.
    If I omit the worksheets.add statement, the loop happily iterates through the headers, selecting each of them.

    any ideas?
    cheers,
    Kieran

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: worksheets.add breaks Do loop in Excel 2010?

    It likely is caused by the adding of the new worksheet and that sheet becoming the active one.

    Here's the same thing using Range instead.

    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    02-12-2012
    Location
    Victoria
    MS-Off Ver
    Excel 2010, Excel 2013/64
    Posts
    23

    Re: worksheets.add breaks Do loop in Excel 2010?

    Thanks for your input David, but this causes exactly the same issue.

    It exits without error at
    Please Login or Register  to view this content.


    ---------- Post added at 12:58 PM ---------- Previous post was at 12:53 PM ----------

    Geez.. I dunno. Scratching my head, because the logic (in both) looked good to me, I thought 'let's restart'.
    So I just restarted Excel + my computer, and now both work (including the one I posted my query about).

    Sorry for the bother, and thanks again for your time David.

    Excel must have been having a brain hemorrhage.

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: worksheets.add breaks Do loop in Excel 2010?

    I don't know either. It worked as written in my machine. I'd have to see the workbook.

    Try adding
    Please Login or Register  to view this content.
    just before to see if it is generating an error.

+ 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