+ Reply to Thread
Results 1 to 4 of 4

Use variables defined in sub in my function

  1. #1
    Registered User
    Join Date
    05-18-2012
    Location
    Norwalk, CT
    MS-Off Ver
    Excel 2010
    Posts
    80

    Use variables defined in sub in my function

    Hi,

    When I write a function, do I have to redefine my variables? What If i want to use a variable that I defined in my sub?

    For example:

    Please Login or Register  to view this content.
    How do I use Wa in my function without redefining it?

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Use variables defined in sub in my function

    pass it to the function as an argument
    Josie

    if at first you don't succeed try doing it the way your wife told you to

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

    Re: Use variables defined in sub in my function

    You could either declare Wa publicly.
    Please Login or Register  to view this content.
    Or, which is probably much better, pass it as an argument to the function.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Use variables defined in sub in my function

    Hi niko,

    not sure what you mean. You don't have to redefine your variable, but you can assign different values to it later on. After you assigned the value "Worksheets(2)" to your variable, you can use it instead of it. Like this:
    Please Login or Register  to view this content.
    is the same as
    Please Login or Register  to view this content.
    If your want to change the value, you just make another "Set" statement. For example
    Please Login or Register  to view this content.
    edit: never mind, I completely misunderstood.

+ 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