+ Reply to Thread
Results 1 to 5 of 5

Define variable in macro than calling that macro inside another macro

  1. #1
    Forum Contributor
    Join Date
    02-05-2015
    Location
    czech
    MS-Off Ver
    2010
    Posts
    172

    Define variable in macro than calling that macro inside another macro

    I would like to define variables in one macro then I wolud like to call that macro inside another.

    A made new module "Module1! and tried this code:

    Sub Myvars()
    rp="A"
    End Sub

    Sub Callsub()
    Call Module1.Myvars
    Cells(3,3)=rn
    End Sub

    But it doesn't work. Can you help me please?

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Define variable in macro than calling that macro inside another macro

    The module is just the location of a procedure / macro. If you want to call a procedure from another module entirely, you need to make the subroutine Public.

    If you want to simply call a procedure from with the same module, you only need to use its name or along with the Call function.


    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.

    And then here's an example of module to module:

    Module1:

    Please Login or Register  to view this content.
    Module2:

    Please Login or Register  to view this content.
    Last edited by daffodil11; 08-21-2015 at 09:58 AM.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    7,318

    Re: Define variable in macro than calling that macro inside another macro

    Maybe:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  4. #4
    Forum Contributor
    Join Date
    02-05-2015
    Location
    czech
    MS-Off Ver
    2010
    Posts
    172

    Re: Define variable in macro than calling that macro inside another macro

    Thanks, line "Dim rn As String" outside procedure did it.

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    7,318

    Re: Define variable in macro than calling that macro inside another macro

    Glad to help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Calling a macro inside another macro
    By MikeMeerkat in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-15-2015, 05:30 AM
  2. [SOLVED] Define a Variable that equals the Row Number I have selected when I start the Macro
    By gle in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-16-2013, 03:07 PM
  3. Button command doesnt work while calling a macro from a macro
    By bryan444 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2012, 09:39 AM
  4. Maintain Variable Value when calling a new macro
    By guinness4breakfast in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2009, 06:23 PM
  5. Define worksheet as variable, then call in macro
    By bugman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2005, 01:20 PM
  6. [SOLVED] Calling a variable macro
    By Hari Prasadh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2005, 05:05 AM
  7. Variable with no Value inside Macro Equation??
    By TEAM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2005, 03:05 PM

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