+ Reply to Thread
Results 1 to 6 of 6

Macro/Sub Name and Description

  1. #1
    Forum Contributor
    Join Date
    07-07-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    500

    Macro/Sub Name and Description

    Greetings,
    I was wondering what is the best way to label/name macros/subs. Is it best to use a short label/name or can the description be added as well? I have a lot of macros to write and wanted to make sure I started out on the right path.
    See examples below:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Macro/Sub Name and Description

    I think this is one of those things that comes down to personal taste. There will be an upper limit to procedure name length, but if you're getting anywhere near that then it's time to rethink.

    I tend to use short but descriptive names, so I'd use "ConsolidateMonthlyData" rather than "CMD" as I'll no doubt forget what the latter stands for.

    I find short descriptive names best as if I need to call that sub elsewhere in the project code I can easily tell what I'm calling and why just from the name. This is especially helpful if you're coming back to a piece of code after a long time or when you're handing a project over to someone else to maintain.

    If you need more description than is sensible in a sub title then use a few comment lines at the start to explain what the sub is for.

    Personal opinion, of course.

    BSB

  3. #3
    Forum Contributor
    Join Date
    07-07-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    500

    Re: Macro/Sub Name and Description

    BSB,
    Thank you for the suggestion - I was concerned having a longer procedure name may slow down the speed of the macro.
    Also, is there a way to determine where the macro is being used? In other words, if for some reason I forget where the code is assigned to, how would I "search" for it?

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Macro/Sub Name and Description

    I agree 100% with BadlySpelledBuoy on how to choose good names, and also that's it's somewhat personal. The same guidance applies to variable names.

    I always write code as if someone else will maintain it. If I look at my own code 6 months later, I might as well be somebody else. Do your future self a favor.

    The length of the name has absolutely no effect on the speed of the macro.

    The only way I know of to find out where a Sub is called is to do a find (CTRL+F), search for the name of the sub and check "Current Project".

    You didn't ask, but if you are looking at a place where the sub is called and want to see the code for that sub, highlight the name of the sub in the call, right-click, and select Definition.

    BTW the With statement is a powerful tool but if you only have one line of code inside it, it doesn't buy you anything. What you did it not wrong but in this case it doesn't provide any advantage over using a single line:

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro/Sub Name and Description


    Hi !

    If you are not in a team, it's just a personal practice …

  6. #6
    Forum Contributor
    Join Date
    07-07-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    500

    Re: Macro/Sub Name and Description

    6StringJazzer,
    Thank you for the comment about removing the WithStatement. I will going forward.
    As always, I am thankful for the Forum and all your suggestions.

+ 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] Drop List with a description but once chosen description disappear
    By dezspert22 in forum Excel General
    Replies: 22
    Last Post: 12-19-2016, 05:24 PM
  2. Macro to search a cell description and return a date
    By kevthomas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-16-2015, 12:25 PM
  3. Part-Number - Description lookup macro
    By AAdach in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-19-2015, 02:37 PM
  4. Change Macro Button Description for Hover Over
    By Chaba in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-22-2014, 03:30 PM
  5. Macro to replace any 10 digit number in the cell which has other description
    By harisha19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2014, 05:17 AM
  6. [SOLVED] Need Macro to pull only interface number not description.
    By watchdog4400 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2013, 08:39 AM
  7. Macro to move file(s) based on wildcard description
    By samf88 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-05-2011, 05:51 AM

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