+ Reply to Thread
Results 1 to 5 of 5

Pass variable from a subroutine to another sub

  1. #1
    Registered User
    Join Date
    06-14-2012
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2007
    Posts
    3

    Pass variable from a subroutine to another sub

    I have a large macro that exceeded the allowable size of a macro so I broke it into a couple of subs. I need to pass variable from one subroutine, where the variables are counting the number of occurances of certain types of records and then passing to another subrountine where I write out a summary line for each variable with its respective value.

    [Sub MainMacro()
    Call sdcdir
    Call outsum
    End Sub

    Sub sdcdir()
    Dim UT10APMDevcnt As Integer
    If assetdept = "xx-xx-xxxx" Then
    UT10APMDevcnt = UT10APMDevcnt + 1
    Elseif …
    End sub

    Sub outsum()
    Sheets("sheet4").Activate
    s = s + 1
    Cells(s, 8).Value = UT10APMDevcnt
    s = s + 1…

    ][/CODE]

  2. #2
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Pass variable from a subroutine to another sub

    Please Login or Register  to view this content.
    Hope this helps
    Regards,
    Vandan

  3. #3
    Registered User
    Join Date
    06-14-2012
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Pass variable from a subroutine to another sub

    Thanks Vandan - so I have around 200 conditions in sdcdir() so in the Sub outsum do I list all 200 variable in the Sub outsum(n1...n200)? Thanks

  4. #4
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Pass variable from a subroutine to another sub

    may be, in you case this is better. Declare module level variables so you do not have to pass them from sub to sub

    Please Login or Register  to view this content.
    more about variables at: http://www.ozgrid.com/VBA/variable-scope-lifetime.htm

  5. #5
    Registered User
    Join Date
    06-14-2012
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Pass variable from a subroutine to another sub

    Thanks Vandan - this works well

+ 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