+ Reply to Thread
Results 1 to 10 of 10

Basic Loop Trouble - need to convert active sheet to integer

  1. #1
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Question Basic Loop Trouble - need to convert active sheet to integer

    I'm new to usign loops and I've run into a bit of trouble, I need to use a loop to add a value of 1 to the workseets name on each repetition. The worksheets are all named with single numbers but I'm not sure how to convet the active sheet reference into an integer t hat I can use to add a value to. I also tried



    Please Login or Register  to view this content.
    I also tried

    Please Login or Register  to view this content.
    I also tried

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

    Thanks
    Last edited by mick86; 09-16-2012 at 03:39 PM.

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

    Re: Basic Loop Trouble - need to convert active sheet to integer

    Hi Mick,

    If it's the name - you've got to use quote marks, because the name is a string - when you just use a number, that's the sheet index.
    Please Login or Register  to view this content.
    or something similar!
    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

  3. #3
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Basic Loop Trouble - need to convert active sheet to integer

    I tried like this but it gets stuck on Sheet "2"

    Please Login or Register  to view this content.
    Last edited by Cutter; 09-18-2012 at 07:19 PM. Reason: Removed whole post quote

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

    Re: Basic Loop Trouble - need to convert active sheet to integer

    Please Login or Register  to view this content.
    It all depends on how your sheets are named - this will give you Sheets(2) to Sheets(21)

    If you want "Sheet2" to "Sheet21" then you could use:

    Please Login or Register  to view this content.
    Last edited by xladept; 09-17-2012 at 03:06 PM.

  5. #5
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Basic Loop Trouble - need to convert active sheet to integer

    So much simpler, I was perhaps coming at things from the wrong direction.

    My sheet names do not contain the word "sheet', they just have numbers.

    Your code almost works, though the fact that the 1st sheet i created is called "index" seems to be a problem. The reference style you suggested seems to refer to the sheets number derived from its creation time rather than the sheets name.

    As you write it it starts on the sheet named "1" which is (sheet 2) according to the visual basic menu and it runs up until sheet "20" (which is technically sheet 19).

    If I change the code to:


    Please Login or Register  to view this content.

    This is a work around for the problem. Perhaps if quotation marks were included with in the brackets I'd be able to refer to the exact sheet name

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    I'll be able to use that in multiple locations where I had previously been doing things manually.
    Last edited by Cutter; 09-18-2012 at 07:20 PM. Reason: Removed whole post quote

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

    Re: Basic Loop Trouble - need to convert active sheet to integer

    The "i" wont work.

  7. #7
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Basic Loop Trouble - need to convert active sheet to integer

    Neither way seems to work

    Please Login or Register  to view this content.

    This doesn't work either

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

    Re: Basic Loop Trouble - need to convert active sheet to integer

    How about a mockup? OR:

    Please Login or Register  to view this content.
    Last edited by xladept; 09-18-2012 at 02:25 PM.

  9. #9
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Basic Loop Trouble - need to convert active sheet to integer

    Attached a mock up, it works as is but refers to the sheets index numbers rather than the sheets names. I was initially hoping to do it by sheet name. That said it works alright as it is.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    05-05-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Basic Loop Trouble - need to convert active sheet to integer

    Quote Originally Posted by xladept View Post
    How about a mockup? OR:

    Please Login or Register  to view this content.
    This is a good option that works around needing to name the involved worksheets.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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