+ Reply to Thread
Results 1 to 2 of 2

worksheets variables from another sub not working

  1. #1
    Registered User
    Join Date
    04-20-2011
    Location
    Swe
    MS-Off Ver
    Excel 2003
    Posts
    9

    worksheets variables from another sub not working

    Hey!

    NVM I SOLVED it, apparantly I declared sheetz as a string when it was actually a int! Thanks

    I have two subs, when taking a variable (sheetz)from predict1 to predict and using it within worksheets(variable) it doesn't work. However if I declare sheetz within the same sub (predict) it works fine.

    Following does not work:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

    Following works:

    Please Login or Register  to view this content.
    This also works:
    Please Login or Register  to view this content.

    I've got about 10 different predict (predict1, predict2) etc subs with different values so I need it to work.
    Note that other transfered values works just fine it's only the worksheet that doesn't.
    The code is much shorter I've just simplified it to project the single problem.

    Thank you!!
    Last edited by Leia; 05-11-2011 at 04:00 AM.

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: worksheets variables from another sub not working

    Hi,
    in my opinion, the problem is that you declare Sheetz argument of sub predict to be of type string. So, when you call Worksheets(sheetz) it is looking for a sheet named 1 and not for the first sheet in the workbook.
    Change the declaration to be

    Please Login or Register  to view this content.
    and I think it will work.

    By the way, my personal preference is not to use variables with the same name...

    Buran
    If you are pleased with a member's answer then use the Star icon to rate it.

+ 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