Skip to main content
Commonmark migration
Source Link

###Just to be clear

Just to be clear

###Just to be clear

Just to be clear

added 229 characters in body
Source Link
Raystafarian
  • 7.3k
  • 11
  • 15

I keep a text file of my most used excerpts

enter image description here

that I can pull from for common mistakes. e.g.

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.

I keep a text file of my most used excerpts that I can pull from for common mistakes. e.g.

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.

I keep a text file of my most used excerpts

enter image description here

that I can pull from for common mistakes. e.g.

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.

added 229 characters in body
Source Link
Raystafarian
  • 7.3k
  • 11
  • 15

###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.


###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.

added 229 characters in body
Source Link
Raystafarian
  • 7.3k
  • 11
  • 15
Loading
Source Link
Raystafarian
  • 7.3k
  • 11
  • 15
Loading