VBA

Visual Basic for Applications (VBA) enables building user-defined functions (UDFs), automating processes and accessing Windows API and other low-level functionality through dynamic-link libraries (DLLs). VBA is closely related to Visual Basic and uses the Visual Basic Runtime Library, but it can normally only run code within a host application rather than as a standalone program. It can, however, be used to control one application from another via OLE Automation. VBA is built into most Microsoft Office applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

Binomial Distribution
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac Newton by several years in publishing his work. Actually, it was Jacob's brother Johann Bernoulli (1667-1748), an academic who made sense of Leibniz's notes and was primarily responsible for getting Leibniz's "Calculus" published. In fact, it was Johann that coined the term "Integral" (Leibniz called it sums), and may have even been responsible for the calculus symbology. If the name Bernoulli sounds familiar and you're an engineer, it's probably Johann's son Daniel Bernoulli you recall.

For over 300 years, mathematicians and statisticians have used the Binomial Distribution to group and model real world observations and is the basis of many other statistical distributions.

Here are my spreadsheets if you want to take a look at them:
https://filedb.experts-exchange.com/incoming/2017/03_w13/1153243/N-16-BBD.xlsm
https://filedb.experts-exchange.com/incoming/2017/03_w13/1153244/N-35-BBD.xlsm
https://filedb.experts-exchange.com/incoming/2017/03_w13/1153245/N-40-BBD.xlsm
https://filedb.experts-exchange.com/incoming/2017/03_w13/1153246/N-64-BBD.xlsm
1
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Excel Error Handling Part 3 -- Run and Fix Bugs
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel.

Part 1 of this series discussed basic error handling code using VBA.
http://www.experts-exchange.com/videos/1478/Excel-Error-Handling-Part-1-Basic-Concepts.html

Part 2 went in depth on how the VBA  to copy values to blank cells works, and how to loop.
http://www.experts-exchange.com/videos/1498/Excel-Error-Handling-Part-2-VBA-to-Copy-Values-Down-to-Blank-Cells-in-an-Excel-Column.html

Although helpful, it is not necessary to watch parts 1 and 2 before this lesson.

This lesson runs code to see what it does and then breaks working code so we can explore errors.  We run and fix, debug, compile, use and not use Option Explicit, step through code while it is running, look at the watch window to see values of variables, set and clear breakpoints, stop, continue running, and learn how debugging and error handling work.

01. For a list of macros, press Alt-F8


   When you are in an Excel Workbook, press Alt-F8 for a list of Macros.

02. To go to VBA, press Alt-F11


   When you are in an Excel Workbook, press Alt-F11 to go to the Visual Basic Editor (VBE) where you can write Visual Basic for Applications (VBA).

03. To watch variable values, press Ctrl-W


   When you are in VBA code, press Ctrl-W to open the Watch window and set expressions to watch the value of.  If a variable name is highlighted when Ctrl-W is pressed, it will be filled in the Expression.

04. Stop


   Add a Stop statement to the code to cause the code to stop on that line when it runs.

05. To single-step, press F8

1
Fix Code to fill Missing data in Excel. Loop through spreadsheet in VBA.
This Experts Exchange lesson shows how to use VBA to loop through rows in Excel.  In order to sort, filter, and use database features, there needs to be a value in each column for every row. When data arrives with values missing, code to copy values where it is blank can be run.

This lesson shows the manual process to fill blanks, and the VBA code to implement it.

This is Part 2 in a 3-part series to discuss error handling in Excel.

Part 3 of this series will add errors to the code and then show how to fix them.  Part 1 of this Experts Exchange series suggested basic error handling code.

01. Set up the error handler


   At the top of the code for your procedure, the error handler is set up using     On Error GoTo Proc_Err

02. Dimension Variables


   Declare variable names and data types that will be used in this procedure.

03. Initialize Variables


   Initialize the values of variables that will be used in this procedure.

04. Calculate Variables


   Calculate the values of variables that be determined.

05. Give User a Chance to Back Out


   Issue a message box to the user and allow them to stop the process.

06. Determine the Last Row


   Determine the last row on the worksheet that needs to be written to.

07. Loop through each Row of Data and Save or Write Value


   Loop through each row and either save the value that is there, or write the last value saved if a value is needed.

08. Continue Looping until Done


   Continue looping until all values in the specified column are written.

09. Exit Code


   After the procedure code, a line label for the exit code (Proc_Exit: ) is used to signify what happens at the end of the procedure. This is code to gracefully exit.

10. Error Handling Code

0
 
LVL 21
This is Part 2 in a 3-part series to discuss error handling in Excel.  It can be watched independently of the other videos.  This presentation focuses on automating a manual process to copy values from one row to the next in a column of an Excel spreadsheet.

You will learn how to loop through rows using VBA.  This example copies values to blank cells, but you could do something else in your loop.

Part 3 of this series will add errors to the code and then show how to fix them.  
http://www.experts-exchange.com/videos/1518/Excel-Error-Handling-Part-3-Run-and-Fix-Bugs.html

Part 1 of this series reviewed basic error handling code.
http://www.experts-exchange.com/videos/1478/Excel-Error-Handling-Part-1-Basic-Concepts.html

Attached is the download file for this lesson, and the next: Books_ErrorHandling_02_Code2_CopyDownBlanks.xlsm
Books_ErrorHandling_02_Code2_CopyDo.xlsm
0
Basic Error Handling code for VBA and Microsoft Office
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code.

This lesson, Part 1, is the basics.  Whether you are writing VBA for Excel, Access, Word, or another Microsoft Office application,  basic error handling is the same.

01. Set up the error handler


   At the top of the code for your procedure, the error handler is set up using     On Error GoTo Proc_Err

02. Exit Code


   After whatever your procedure does, a line label for the exit code (such as Proc_Exit: ) is used to signify what happens at the end of the procedure. This can be code to cleanup object variables, or simply code to gracefully exit.

03. Error Handling Code


   After the exit code, a line label for the error handling code (such as Proc_Err: ) is used to begin what happens if there is an error.
Books_START_ErrorHandling_CopyDownB.xlsm
Books_ErrorHandling_CopyDownBlanks_.xlsm
2
 

Expert Comment

by:chris pike
For someone who is trying to wrap their brain around VB for the first time, this video is starting to shed light on the subject.
Well done video, very helpful.

Thanks so much.
I will definitely look out for more videos from crystal (strive4peace).
0
 
LVL 21
thank you, Chris and you're welcome  ~ if you have any questions about basic error handling, please post them here.
0

VBA

Visual Basic for Applications (VBA) enables building user-defined functions (UDFs), automating processes and accessing Windows API and other low-level functionality through dynamic-link libraries (DLLs). VBA is closely related to Visual Basic and uses the Visual Basic Runtime Library, but it can normally only run code within a host application rather than as a standalone program. It can, however, be used to control one application from another via OLE Automation. VBA is built into most Microsoft Office applications.