+ Reply to Thread
Results 1 to 8 of 8

Passing Variable to Macro

  1. #1
    Registered User
    Join Date
    09-22-2009
    Location
    Yep
    MS-Off Ver
    Excel 365 Pro Plus
    Posts
    34

    Smile Passing Variable to Macro

    Hi fellows

    I'm trying to use the same varaible results in another sub() as described below.

    The macro count a value from a huge report.:

    Total = Total + (Cells(Rw, colPQty) * Cells(Rw, colRPrice).Value)

    Then, I need to use this Total by another Sub ()

    How to do that??

    Thanks

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Passing Variable to Macro

    You can either
    1) Make the Total an argument in the other sub:
    Please Login or Register  to view this content.
    2) Use a global variable:
    Please Login or Register  to view this content.
    For #2, you declare the variable outside of all procedures, usually at the top of the module.

    Hope that helps
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Passing Variable to Macro

    Hello Dave,

    It looks like the total is a currency value equal to quantity times the price.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Passing Variable to Macro

    Understood Leith. Rather than Long, you'd want to dim the variable as a double.

  5. #5
    Registered User
    Join Date
    09-22-2009
    Location
    Yep
    MS-Off Ver
    Excel 365 Pro Plus
    Posts
    34

    Re: Passing Variable to Macro

    Hey people,

    First of all I would like to thank you for your prompt help.:
    I'm starting use VBA and I unsuccessfull on this issue.
    It seems to be so easy and I don't know where I'm failing.
    See the message error when I tried to run the macro.

    Compile Error :
    Sub ior Function no defined


    Basically this is the part of two sub I'm triyng to fix.

    Please Login or Register  to view this content.
    ---------------
    Please Login or Register  to view this content.
    Thanks once again
    Last edited by Leith Ross; 06-09-2010 at 04:40 PM. Reason: Added Code Tags

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Passing Variable to Macro

    I think if you are calling a sub that is run from a button click, you have to use:

    Please Login or Register  to view this content.
    Props to Andy Pope for teaching me this fact just the other day!
    Last edited by davegugg; 06-09-2010 at 04:56 PM. Reason: Props

  7. #7
    Registered User
    Join Date
    09-22-2009
    Location
    Yep
    MS-Off Ver
    Excel 365 Pro Plus
    Posts
    34

    Smile Re: Passing Variable to Macro

    I tried this but still not working. The macro didn't capture anything.

    If frmBOM.OptBOMYes = True Then
    ws.Cells(10, "M").Value = BomCost.Value
    End If

    thank you

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Passing Variable to Macro

    Mota, please take a few minutes to read the forum rules, and then edit your post to add CODE tags.
    Entia non sunt multiplicanda sine necessitate

+ 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