{"id":388,"date":"2017-07-19T10:27:30","date_gmt":"2017-07-19T15:27:30","guid":{"rendered":"https:\/\/www.onlc.com\/blog\/?p=388"},"modified":"2017-07-19T10:27:30","modified_gmt":"2017-07-19T15:27:30","slug":"excel-20132016-vba-programming-beginners","status":"publish","type":"post","link":"https:\/\/www.onlc.com\/blog\/excel-20132016-vba-programming-beginners\/","title":{"rendered":"Excel 2013\/2016 VBA Programming for Beginners"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Learning how to use the VBA (Visual Basic for Applications) programming language in Excel will give you the ability to create actual data applications in <\/span><a href=\"https:\/\/www.onlc.com\/excel-training-classes-certification.htm\" target=\"_blank\"><span style=\"font-weight: 400;\">Microsoft Excel<\/span><\/a><span style=\"font-weight: 400;\">. By combining the two, you wield the power of Excel and you can use VBA to automate its functionality. Let\u2019s take a look at some of the things that you might learn if you take a class on\u00a0<\/span><a href=\"https:\/\/www.onlc.com\/outline.asp?ccode=WEXP16\" target=\"_blank\"><span style=\"font-weight: 400;\">Programming Excel with VBA<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Working with Procedures and Functions<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">These small building blocks of code allow you to encapsulate sets of instructions that can be executed multiple times and called from multiple locations. Think of them as useful tools that can be used whenever you need them. They prevent you from needing to write the same code over and over since they can be written in one block and called from anywhere. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">They not only cut down on redundant code but reduce errors as well. A bug can be fixed in one function and everywhere that it is called can reap the benefit instead of having to fix it in multiple locations.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Understanding Objects<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Objects are used to define things or entities in code. Objects consist of properties, methods and events. The properties help to describe the object. A real-world example of an object could be a boy. Some of the boy\u2019s properties or attributes could be hair color, eye color, height, weight, etc. Those things describe what the boy looks like. The methods describe what the boy can do. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, the boy can run, jump and play. In code, these methods would be procedures and functions with instructions on how the boy completes these tasks. Finally, events are instructions on what to do when a specific event occurs. An example of this would be if someone were to throw a ball to the boy. If a ball is thrown, then the event would contain instructions on how to catch the ball.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Using Expressions, Variables and Intrinsic Functions<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">These structures are intended to help make your life easier. You can build expressions by combining numbers and Excel\u2019s built-in operators to perform any calculation that you can think of. You can also use variables that can be set by expressions and use them throughout your code. Variables can also be passed into functions as parameters. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Functions and procedures are larger and more complex combinations of smaller expressions and variables. Functions are like macros in that they do the same thing over and over without you having to program the same thing each time you want to execute the same functionality.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Controlling Program Execution<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">VB code can be inserted into Excel to control the execution of your programs. This code can be used to fire when events occur, such as when the text in a text box changes or a button is clicked. You can also pop up message boxes and other dialogues to ask the user questions or provide cues on inputs or validations to help guide the user through your functionality more gracefully.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Working with Forms Controls<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Forms and controls can be constructed to make for a more robust user interface. Simple controls, such as text boxes, labels and buttons can be organized on a form to help create screens to allow users to input the desired data to execute your functionality. This is much nicer than just entering values into boxes on a spreadsheet and provides for a richer user experience.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Working with the Pivot Table Object<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Pivot tables are very powerful data organization structures. They are also very popular in Excel and can be created easily with the included wizard. The <\/span><a href=\"https:\/\/msdn.microsoft.com\/en-us\/vba\/excel-vba\/articles\/pivottable-object-excel\" target=\"_blank\"><span style=\"font-weight: 400;\">Pivot Table Object<\/span><\/a><span style=\"font-weight: 400;\"> is just like the objects we discussed above except that it has already been written by Microsoft to include the most popular functionality that is performed on pivot tables. You get the properties, methods and events most used to manipulate pivot tables without having to write it yourself. It\u2019s basically canned functionality that is provided for you.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Debugging Code<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">If you find that your code isn\u2019t exactly behaving as planned, VBA provides you with a debugger. The debugger gives you the ability to analyze exactly what is happening in your code and find where it is breaking. It also allows you to momentarily stop the execution of your code and step through it to figure where the error is occurring. You can see the values of your variables at their current state and even set breakpoints to automatically stop execution at specific points in your code. This way you can determine exactly what is happening at that place and in the particular context that the code is being used.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Handling Errors<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">VBA has built in statements to make catching and handling errors easy. The \u201cOn Error GoTo\u201d statement tells the program where to go if an error occurs. The usual practice is to send it to an error handling routine that will trap it and log it or display it. Then the error handling code can dispose of the error gracefully so that the program can continue execution. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The \u201cResume\u201d and \u201cResume Next\u201d statements tell the program what to do after the error has been appropriately handled. Error handling should prevent the program from crashing and provide the programmer with information they can use to eliminate the scenario altogether. At the very least, errors should be handled gracefully and not prevent further program execution.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Knowing how to use VBA and the structures outlined above will give you many advantages over competition in the eyes of potential employers. If you can unlock the capabilities of Excel and automate its powerful functionality, then you will truly be a valuable asset to any company. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Anyone can learn to use the basics of Excel, but not everyone can pair it with VBA programming to produce a data application. Learn how to write VBA in Excel today by attending an <\/span><a href=\"https:\/\/www.onlc.com\/rci-remote-instructor-faqs.htm\" target=\"_blank\"><span style=\"font-weight: 400;\">instructor-led class at ONLC<\/span><\/a><span style=\"font-weight: 400;\">. We can train you to be an expert VBA programmer in no time in one of our 300 convenient nationwide classrooms. <\/span><a href=\"https:\/\/www.onlc.com\/contact-onlc.htm\" target=\"_blank\"><span style=\"font-weight: 400;\">Contact us today<\/span><\/a><span style=\"font-weight: 400;\"> to find out more! <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learning how to use the VBA (Visual Basic for Applications) programming language in Excel will give you the ability to create actual data applications in Microsoft Excel. By combining the two, you wield the power of Excel and you can use VBA to automate its functionality. Let\u2019s take a look at some of the things [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":389,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[2],"tags":[],"class_list":["post-388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-excel"],"aioseo_notices":[],"modified_by":"blogadmin","_links":{"self":[{"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/posts\/388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/comments?post=388"}],"version-history":[{"count":2,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/posts\/388\/revisions"}],"predecessor-version":[{"id":391,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/posts\/388\/revisions\/391"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/media\/389"}],"wp:attachment":[{"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/media?parent=388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/categories?post=388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/tags?post=388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}