Monday, January 28, 2013

Intro to Visual Basic

Enabling Macros in Excel.
1.  Choose File -> Excel Options -> Trust Center -> Trust Center Settings -> Macro Settings
2. Click "Enable all Macros"
3. Click "Ok" button.

Showing Developer Tab in Excel.
1.  Choose File -> Excel Options -> Popular
2. Check the "Show Developer Tab in the Ribbon"
3. Click "Ok" button.

First Code - VB Intro.xlsm


Sub dummy()
 '
 ' dummy Macro
 ' just messing around

 ' assigning variables
    x = Range("a5").Value
    fx = (x ^ 2 - 10 * x + 9)
    fprime = x * 2 - 10

 'formula for newton method
    nextiterate = x - fx / fprime

 'assigning b1 for next iterate
    Range("b5").Value = nextiterate

End Sub

Notes:
1. If we click on the "Macros" Button on the ribbon, we can create, edit, delete and run the macro.
2. If we click on the "Record" button in the ribbon and do some stuff in Excel, it records what you were actually doing for future reference. Make sure to click "Stop" once we're done.
2. If we click on the "Visual Basic" button on the ribbon. The entire Visual basic program will run.

Visual Basic Program
1. On the upper right corner shows the "Project - VBA Project" which shows the workbook's sheets and macro.
2. On the lower right corner shows properties  the active sheets.

No comments:

Post a Comment