I keep a text file of my most used excerpts
that I can pull from for common mistakes. e.g.
Integers - [integers are obsolete](http://stackoverflow.com/questions/26409117/why-use-integer-instead-of-long/26409520#26409520). According to [msdn](https://msdn.microsoft.com/en-us/library/office/aa164506(v=office.10).aspx) VBA *silently* converts all integers to `long`.
[Standard VBA naming conventions](https://msdn.microsoft.com/en-us/library/1s46s4ew(v=vs.140).aspx) have `camelCase` for local variables and `PascalCase` for other variables and names.
I tell them what is wrong, a brief reason why it is wrong and links to read if need be. Another example is
Comments - ["code tell you how, comments tell you why"](http://blog.codinghorror.com/code-tells-you-how-comments-tell-you-why/). The code should speak for itself, if it needs a comment, it might need to be made more clear. If not, the comment should describe *why* you're doing something rather than *how* you're doing it. Here are a [few reasons](http://programmers.stackexchange.com/a/254979/125931) to avoid comments all together.
I could easily write a blog post on my website that explains the why or link to another answer of mine - but then they need to sift through the rest of the other answer to find what I'm talking about.
I could link to someone else's why e.g.
Mathieu Guindon (Microsoft Excel MVP, 2018) [reasons](https://rubberduckvba.wordpress.com/2018/01/12/progress-indicator/) that blah blah
For beginner VBA questions I always feel like it's important to give a reference as to what I'm talking about because the majority of beginner VBA questions usually don't have any background in coding in the first place (myself included some 5 years ago).
For something like c# I might want to link to a Jon Skeet answer.
And maybe for something as basic as "you can use such and such namespace" I'm sure I could find a beginner tutorial or even a reference to an article or book that can help with the why of the basics - not the how.
I want to give the asker as much information as they could want even if they don't want it, for the same reason I want to explain what I can at other sites - for future visitors.
It's not like saying
Look at [link]
you should do this because of reason. If you want more reference see [link].
I'm still giving them the why and if the link goes dead my statement still works.
Just to be clear
My answer would look something like
For Each x in Collection 'iterate through items
You didn't type your variable
x. When you don't define your variable, VBA will declare it as a Variant, which are objects.
Always turn on
Option Explicit. You can have it automatically by going to Tools -> Options in the VBE and checking the Require Variable Declaration option. This way if you have any variables not defined, the compiler will let you know.
You also have a comment telling me exactly what the code is doing, which should be evident. Comments - "code tell you how, comments tell you why". The code should speak for itself, if it needs a comment, it might need to be made more clear. If not, the comment should describe why you're doing something rather than how you're doing it. Here are a few reasons to avoid comments all together.
If it's not clear, maybe you should improve your naming - give your variables meaningful names.
The only parts that I didn't copy from my document are in italics
That's four snippets from my text file which would stand alone without the links, but the links would be very helpful for someone that wants to know why. I'm also using their code as the example.
Obviously this only works for common beginner mistakes, but that's what we're talking about here. This is just works for me in this particular language.