+ Reply to Thread
Results 1 to 6 of 6

How do Subroutines work

  1. #1
    Registered User
    Join Date
    02-03-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    37

    Question How do Subroutines work

    I am trying to run understand how sub routines work. They are very basic so I can understand the concept.
    I have a 3 Sub Routines, 1 being the Main one. Sub Main(), Sub Formatting(), Sub Borders
    Here is my code. I am getting a Compile error: Sub or Function Not Defined
    I want to run "Main" then format and border A1 using Sub routines "Formatting" and "Borders".
    What am I doing wrong? Is there a difference in keeping subs in different modules or in the same one?


    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Re: How do Subroutines work

    Hi,
    See comments in code below:
    Quote Originally Posted by 1vision View Post
    I am trying to run understand how sub routines work. They are very basic so I can understand the concept.
    I have a 3 Sub Routines, 1 being the Main one. Sub Main(), Sub Formatting(), Sub Borders
    Here is my code. I am getting a Compile error: Sub or Function Not Defined
    I want to run "Main" then format and border A1 using Sub routines "Formatting" and "Borders".
    What am I doing wrong? Is there a difference in keeping subs in different modules or in the same one?


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-03-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: How do Subroutines work

    Thanks.

    Ok, nice I am understanding the concept now. Do the subroutines work the same if they are all in 1 module as they would if they are all in separate modules?

  4. #4
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Re: How do Subroutines work

    Some find it easier to split into separate Modules, you can name the Module for later easier deciphering etc.

    If the sub is called by >1 routine, then this would save code repetition.

    Your sub's could be incorporated in a single sub instead of 3.

  5. #5
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: How do Subroutines work

    Here is another approach to the same problem using an internal routine approach

    Please Login or Register  to view this content.

    Cheers

    Jmac1947

    1. Please consider clicking on the * Add Reputation if you think this post has helped you
    2. Mark your thread as SOLVED when question is resolved

  6. #6
    Registered User
    Join Date
    02-03-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: How do Subroutines work

    Thanks for the tips.

+ 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] can't debug some subroutines in my project, locked subroutines
    By florin_excel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-28-2012, 01:16 PM
  2. If/Then for invoking subroutines or End?
    By rodrigt in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-15-2010, 05:02 AM
  3. Combining Subroutines
    By jj72uk in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-18-2009, 04:02 AM
  4. Calling subroutines
    By kevlaw in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-02-2008, 08:13 AM
  5. Calling SubRoutines
    By diannk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-18-2008, 03:51 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