+ Reply to Thread
Results 1 to 6 of 6

Calling Procedure or Function inside another Procedure - variables problem

  1. #1
    Registered User
    Join Date
    05-18-2015
    Location
    Bratislava
    MS-Off Ver
    Office 2007
    Posts
    33

    Calling Procedure or Function inside another Procedure - variables problem

    Hi guys.
    I have stucked on below thing. I believe it's pretty easy, but so far not for me :-)

    Below Procedure just adds to column B info based on info in column C. Nothing more and it works OK. Please, is possible to replace For Next cycle I have there with calling another Procedure ? My problem is: if I create new procedure, should I again define all variables there as I did in this procedure below ? Because my For Next cycle works with variable called "range_count". And this variable I got after all another variables were created. My purpose is just shorten below code.
    Thanks a lot for any ideas.
    --------------------------------------
    Please Login or Register  to view this content.

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

    Re: Calling Procedure or Function inside another Procedure - variables problem

    What would be the value of adding another procedure?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    05-18-2015
    Location
    Bratislava
    MS-Off Ver
    Office 2007
    Posts
    33

    Re: Calling Procedure or Function inside another Procedure - variables problem

    Hi shg. Value is to shorten the code. If I replace big For Next cycle with only "call procedure2()" it would be better. above procedure is not so big, but can be bigger.
    I also ask on this, as this is for me question not only in this case but also in another macros. Because If I always need to declare all variables again, I don't see calling another procedures so much useful. I was thinking, that if I create variable "range_count" and all others as well as Public, would this eliminate the need to declare all variables in Procedure2 again ?

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

    Re: Calling Procedure or Function inside another Procedure - variables problem

    The code is not going to get any shorter in total if you just move it from one procedure to another.

    Any variable used in a procedure must be in scope within the procedure; it must be passed from the calling routine as an argument, or declared locally in the called procedure, or declared at the top of the module in which the called procedure appears, or declared as Public in another standard code module. Just calling a procedure from another procedure does not make the calling procedure's variables visible to the called procedure.
    Last edited by shg; 05-22-2015 at 02:56 PM.

  5. #5
    Registered User
    Join Date
    05-18-2015
    Location
    Bratislava
    MS-Off Ver
    Office 2007
    Posts
    33

    Re: Calling Procedure or Function inside another Procedure - variables problem

    thanks a lot shg. I will then use declaration at the beginning - before - first procedure.

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

    Re: Calling Procedure or Function inside another Procedure - variables problem

    While there is certainly a place for module-level and public variables, the reason should be pretty compelling before doing so. They make code less modular, less reusable, and harder to debug and maintain.
    Last edited by shg; 05-22-2015 at 03:20 PM.

+ 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] Problem with calling another macro (Error 450 and " Expected variable or procedure")
    By Roxner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-07-2013, 04:59 AM
  2. Replies: 0
    Last Post: 10-02-2012, 03:06 PM
  3. Calling a Function in a Procedure
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2010, 02:38 PM
  4. [SOLVED] calling procedure
    By Juggernath in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-13-2005, 08:45 AM
  5. [SOLVED] procedure/function calling
    By raja in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2005, 08:05 AM

Tags for this Thread

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