Hi everyone, Enjoy your watching and please leave your comments below. Don't forget to press SUBSCRIBE my channel for more videos. Thanks for your support.
@RollinShultz5 жыл бұрын
It serves no one for a programmer to take shortcuts in naming and other tasks to save typing. very descriptive names are essential to good coding. It is also essential to use subroutines to compartmentalize the code for simplicity in making changes and separating concerns. It is good to see someone make a video like this for VBA as I get the feeling these things are taken lightly by VBA programmers.
@mikhailk56905 жыл бұрын
I didn't know about Enum, this can really make my code much more readable. Thank you so much for sharing these best practices!
I was able to learn to code by myself but thanking for teaching me best practices. Deeply appreciate it.
@Excelmacromastery5 жыл бұрын
You're welcome Nelson.
@rods64055 жыл бұрын
Been VBAing for 30years did not know about Ctrl+space autocomplete worked on a blank line thanks heaps! Have watched many of your videos and have implemented many changes to speed my code up thanks! Will watch all your videos now!
@dangelorrrr5 жыл бұрын
Enum - learn something new every time I watch your videos. Thanks, Paul!
@Excelmacromastery5 жыл бұрын
You're welcome
@YKazimir5 жыл бұрын
Sir, one of the best Excel youtube channels.
@szabolcsjobbagy302 жыл бұрын
Thank you for teaching the developers, these are very important principles.
@houstonvanhoy21983 жыл бұрын
6:41. Magic numbers, leading into demonstration of ENUMS.
@edwardlee91633 жыл бұрын
Many thanks, it really helps! Appreciate your anonymous effort.
@grzegorz28523 жыл бұрын
Paul, thank u very much for ur videos, they are so super useful. i have learned a lot from u.
@waverider805 жыл бұрын
Good stuff! Putting the dim statements within the code rather than at the top was new to me.
@officetricks63033 жыл бұрын
Continuously watching your video... Great topics and useful in vba.
@RichardCookerly5 жыл бұрын
Just found your channel...loving it! I’ve been a VBA Developer for about 7 years and I learn something from every one of your videos!
@Excelmacromastery5 жыл бұрын
Thanks Richard
@wayneedmondson10655 жыл бұрын
Hi Paul.. these are 7 super tips.. really helpful and will implement them right away.. especially declaring variables where I use them and giving variables friendly names. When first learning, it seems correct to mimic what we see others doing.. so.. bad habits get passed through the generations. Thanks for this great advice to chart my own course and develop my own style. Thumbs up!!
@Excelmacromastery5 жыл бұрын
Thanks very much Wayne. It's true what you say about bad habits being passed.
@FulvioGaggioli2 жыл бұрын
Thank you for your work
@LPAtkins5 жыл бұрын
I prefer to use i,o,p for nested loops. j looks too much like i and i,o,p are right next to each other. Great video.
@TP-om8of2 жыл бұрын
I don’t like i and j either. I use k and l.
@rrrraaaacccc8011 ай бұрын
Great 💯👍
@JimHenderson194 жыл бұрын
I really have learned much from watching your videos.
@Excelmacromastery4 жыл бұрын
That's great to hear Jim.
@tuyoexcelypowerbi5 жыл бұрын
Very useful advices, thanks.
@Excelmacromastery5 жыл бұрын
You're welcome
@trevorclack71785 жыл бұрын
You can get a speed up in code execution by using full referencing as well (e.g. .shData.Range or VBA.Instr). I would also suggest having a unique name for all you VBA projects rather then using the default project name "VBAProject" in order to reduce errors if multiple projects are running at the same time.
@Trucpq5 жыл бұрын
It is valuable knowledge. So useful and so practical. Thanks a lot.
@Excelmacromastery5 жыл бұрын
You're welcome Truc
@Mighty10725 жыл бұрын
Very informative. Thanks
@KcKc-bh6lu5 жыл бұрын
Your suggestion is pretty good practice of variable declaration for VBA because of its interpreter nature. But in compiling languages, declaration must be predefined before any use.
@Excelmacromastery5 жыл бұрын
I'm not sure what you mean. You can define variables as you use them in C# and C++.
@grigull5 жыл бұрын
A different color for parentheses and array values helps a lot :)
@kuldar.3 жыл бұрын
Thank you, your tips are really helpful!
@Excelmacromastery3 жыл бұрын
You're welcome!
@tojtowny4 жыл бұрын
Still exploring what VBA can offer and how to use it, but deffinitly this makes the jurney easier :)
@teguhmarwanto76455 жыл бұрын
Its very good videos. Simple and clear
@Excelmacromastery5 жыл бұрын
Thanks Teguh
@dougtvedt8903 жыл бұрын
At 8:52 when using variables instead of cell references in a For/Next loop, should they be re-set back to 0 before iterating to the next i?
@danielszalok85405 жыл бұрын
Thanks, now I understand why enum is better than constants in this special case! 🙂 A question: do you think 'With-End Width' helps readability? I use it very frequently, but it's so easy to overuse it. How about the readability of if, select case and iif? I would love to watch a video about this 🙂
@DarcyWhyte4 жыл бұрын
Lover your videos. Quick question, when you click it makes little circles. Is that done in post processing or do you have a program that does that in real time?
@sislmira5 жыл бұрын
Just amazing. Thank you for your videos and page.
@hotflashfoto2 жыл бұрын
I agree with your reasoning, but I don't use your execution regarding the declaration of variables. I use the top of the module to declare mine, grouping strings onto one or more lines, as well as other variable types. I also use the LNC, or a modified version of it, to add the type of variable to the front of the name and then supply a descriptive name. For example: Const cstrErrTitle as String = "ERROR MESSAGE TITLE HERE" Private wsMacro as Worksheet, wsSource as Worksheet, wsDest as Worksheet Private strName as String, strAddress1 as String Private lngCount as Long I do this instead of using Dim within each Sub, mostly because I want the value to travel as it's being used, rather than using it only within the Sub and then disposing of it. While I understand the purpose of declaring immediately before use, and it makes it easier to share the code, it also clutters up the code and restricts using the variable's value to that Sub only. I'm sure we won't see eye-to-eye on this, and I don't feel like you're teaching anything that needs to be corrected. It's just that the style of coding that I use is different.
@Anomander15 жыл бұрын
Every vid from you is nice, thank you. I would not delcare variables when you need them, but declare them when you are at the top of your sub or Function. this makes it much easier to transition to another programming language where defining the variables at the beginning is mandatory.
@Excelmacromastery5 жыл бұрын
In most modern languages it's not mandatory😀.
@grahamparker77295 жыл бұрын
Very useful, many thanks 👌🏻
@BenjaminHouot5 жыл бұрын
I don't use anymore "i" or "j" as a variable. I prefer to use "For Row = 1 to NbRows", Or "For Col = 1 to ..." It is more clear.
@joecortizo5 жыл бұрын
People sometimes underestimate the power of a macro... Thanks Master!
@urielramirez275 жыл бұрын
Very simple and powerful tips, thank you. Which software you use to record your tutorials?
@Excelmacromastery5 жыл бұрын
Camtasia
@oceanic141234 жыл бұрын
Great tutorial, thank you. I have a question regarding code behind userforms. I have Textbox, ListBox, ComboBox...with Click events, Functions, BeforeUpdate event, AfterUpdate event and Change event, the code is a mile long and disorganized. Is it possible separate, organize the code by Click event, Function, Update event in regular modules?
@bestscenes14695 жыл бұрын
You're always awesome. Very useful video
@Excelmacromastery5 жыл бұрын
Thanks Daniel
@GersonCarhuapoma5 жыл бұрын
Awesome, Paul, like all the time
@anthonycroft75385 жыл бұрын
Good stuff Paul, although the variable dimming in the body vs top of the procedure would be at the Brexit level of contentiousness within our profession.
@Excelmacromastery5 жыл бұрын
Appears so😂.
@xn3ko5 жыл бұрын
Excelente tips, thank you!
@stevennye50755 жыл бұрын
very informative!
@psychedelarte72575 жыл бұрын
Thanks for this
@Inexpugnablement5 жыл бұрын
Thanks for your vids so interesting and useful ! If I dared, I'd suggest you an eighth: comments. It's so obvious but so necessary.
@rrrprogram86675 жыл бұрын
Beautiful... Loving this channel
@Excelmacromastery5 жыл бұрын
Thanks
@mtotowamungu82595 жыл бұрын
Thank You
@cigmorfil41015 жыл бұрын
The use of I, J etc for loops is a remnant of Fortran where all variables starting with I to N are integers and the rest are floating point (unless explicitly declared). For a loop it would be done an exact number of times so integers would be used for the counter - if a floating point variable was used due to rounding the loop may be executed an extra time.
@gabiold5 жыл бұрын
I always thought "I" just stands for "index"...
@Excelmacromastery5 жыл бұрын
Thanks for the info😀
@dominiquenoel9395 жыл бұрын
In my case, first variable use in for-next loop if always "F" because in ZX81 / ZX spectrum it was same key: first push F to type "For" directly and second push for variable = F is more quickly.
@Excelmacromastery5 жыл бұрын
That's a good reason. My spectrum was the +2 with a whopping 128k .
@davidr58475 жыл бұрын
I really love your videos. I always considered myself a pro in VBA, but after seeing some videos of you I'm not that sure any more lol. However, sometimes I need to make trainingvideos myself for coworkers, what is the software you use for those red boxes to point out certain parts in the screen? I use Camtasia but I haven't found this feature.. Have a great day
@Excelmacromastery5 жыл бұрын
They are under Annotations in camtasia.
@davidr58475 жыл бұрын
@@Excelmacromastery Cannot believe I missed that. Thanks!
@rods64055 жыл бұрын
I avoid using I and L in code and in excel they look to much like each other and 1 in certain fonts. Test which the lowercase L or I in text I l ? even google font is hard to tell. For for loops I use XA XB XC etc
@Laxmanmane0075 жыл бұрын
Also make video on power bi
@maciejdolinski10365 жыл бұрын
Hi Paul, Thank you for great advises! Anyway, I wonder, why Enum is better than Constants? I used constants so far. Can you please comment?
@Excelmacromastery5 жыл бұрын
1. You can group related constants using Enum. 2. You can use the enum as a type once you have created it. e.g. set it as a parameter type. 3. Intellisense shows all the available options when you use the enum in your code.
@ferreira88225 жыл бұрын
Great
@lolguy-x9n5 жыл бұрын
I prefer variables at top not as I use. that way I k ow where to get tbem
@KhalilYasser5 жыл бұрын
Thanks a lot for the awesome hints
@Excelmacromastery5 жыл бұрын
Thank you Yasser.
@igalbitan50965 жыл бұрын
Isn't there any tool to indent code automatically?
@Excelmacromastery5 жыл бұрын
Yes, but no part of the Visual Basic Editor.
@dimonovych5 жыл бұрын
There is Smart Indenter for VBA, which makes your code Indented by only clicking one button. Really convenient.
@KevD_5 жыл бұрын
I did not know that there was a checkbox in the settings to insist that all variables be declared. The first thing I have done for years, before starting a new module is type "OPTION EXPLICIT". I don't even understand why you are allowed to not declare variables! Shakes fist at Microsoft.
@MrWarlls5 жыл бұрын
I prefer to declare the variables on the top of the function/sub. I think it is easier to find them. I am used to start all my variables that have the same type with the same letter (s for the string, a for the arrays, l for long...) For me, it is a good way to identify the king of variable without looking for the statement.
@Excelmacromastery5 жыл бұрын
The variable naming you are referring to is Hungarian Notation which was used a lot in the 1990s and before.
@TP-om8of2 жыл бұрын
I don’t indent my code, I exdent it.
@serdip5 жыл бұрын
Great video, as always. I disagree, respectfully, with the practice of declaring variables immediately before they're used because in some cases it will be necessary to create more variables than would actually be needed if the declarations were centralized at the top of the method. Below is an admittedly contrived example that illustrates why one cannot always declare variables immediately before they're used. =============================================================== Public Sub TestCode() 'Purpose: If current weekday is Monday, print weekday names 'excluding Monday, in ascending order by weekday number 'If current weekday is NOT Monday, print weekday names 'in DESCENDING order by weekday number 'Cannot always declare variables immediately before 'they're used Dim blnIsMonday As Boolean blnIsMonday = (Weekday(Date) = vbMonday) If blnIsMonday Then Dim i As Integer For i = vbSunday To vbSaturday If i vbMonday Then Debug.Print WeekdayName(i) Next i Else 'Dim i As Integer '
@Excelmacromastery5 жыл бұрын
Thanks for your comment. If you need extra variables then you code needs to be rewritten. In your example, the 2 for loops are not necessary. You can write the code so only one is required by using a variable for the start, end and step values. Then you only need one For loop no matter how many conditions.
@igotstoknow25 жыл бұрын
Indenting under Sub is more annoying than helpful.