r/excel • u/JDantes77 • Feb 04 '14
discussion VBA Macro code best practices?
Every programming language has its recommended style and best practices. What are the best practices for VBA code that you follow? What resources would a new coder use to learn these best practices?
Thank you in advance!
18
Upvotes
View all comments
Show parent comment
9
u/[deleted] Feb 04 '14 edited Feb 04 '14
To expand on this, .Copy should be avoided:
Becomes
And even better:
Or if you want values only:
You can also use .Cells instead of "B1" etc. This is great for looping or dealing with columns in terms of integers instead of letters etcl.
Then you have sheet references (using the activesheet is a bad idea usually).
Using this, you'd be able to target hidden sheets etc.