Macro Mondays – How To Name Your Excel Macros


Hello welcome to another #macromonday blog post. Today let’s take a look at naming Macros. Whilst this may seem a strange topic for a blog post, there are a few guidelines that most programmers follow. There are also some restrictions or rules on how to name your macro or macros. They are not difficult to understand or follow. Ler’s cover them off here and that leaves more time for writing more Excel macros!.

What should I name my Excel Macro?

Number one and the most logical part of naming your macro is that the name should describe the macro’s purpose. Would you agree?. If you need to run your macros, come back to your code, or other people pick up your VBA then it really is useful if they have meaningful names. I always try to combine a verb and a noun, which works for me. For example:-

PrintMonthlyReport

DeleteRows

InsertRows

NAMING EXCEL MACROS

Most programmers get into their own style, some use short descriptive names and other much longer. It really is your choice, as long as it works for you. I would always make them as descriptive as possible and keep them more meaningful.

Excel VBA Macro Naming Rules and Restrictions.

Here are some of the guidelines or do’s and don’ts for naming macros.

  • No spaces or periods in the name of the macro.
  • VBA does know the difference between upper and lower cases. Just choose a naming convention you are comfortable with
  • The first character MUST be a letter. But after that, you can use letters, numbers and some available punctuation characters
  • None the following characters can be in a name #,$,&,@,^,* or!
  • If you are naming a Function you need to ensure that the name does not look like a cell reference. For example C123
  • Macro names cannot be longer than 255 characters. I’m not sure that I would ever make a Macro name this long. But that is the restrictions in case you wanted to.

Ok, so today we covered a small number of rules of thumb or guidelines for naming Macros in Excel.

Do you have a naming convention that you stick to?. Share it with us in the comments below.

Next Steps? Do You Want More Macro Help?

You can check out my full list of Macro Mondays blog posts, and the code is always free for you to copy at the end of the blog post.

If you want more tips then sign up for my monthly Newsletter where I share 3 Excel Tips on the first Wednesday of the month and receive my free Ebook, 30 Excel Tips.

excel tips to help you excel at excel

Next Steps?. Do You Want To Learn How Write Excel Macros? Check Out Chandoo’s VBA Classes.

 

Barbara

Barbara is an experienced data analyst with over 20 years of experience. Author of the How To Excel At Excel Top 50 Excel tips Ebook, YouTuber and Excel Blogger.

Recent Posts