Creating Macros in Excel Adding Automated Functionality to Excel & Office Applications
Macros A macro is a series of written instructions or recorded keystrokes and mouse actions. With a single keystroke, users can play back these activities at a much faster speed than those same actions can be performed manually. Macros can help eliminate wasted time and the risk of error that typically occur when performing repetitive tasks.
Two different ways macros are created Keystroke Macros Perform a sequence of operations using keystrokes and the mouse and the application records what you are doing Writing programming code to accomplish a task. Both options use Visual Basic for Applications (VBA). The difference is how the VBA code is created
Customize Ribbon ------ Select DEVELOPER as one of the main tabs File tab Select OPTIONS
Recording 2 Macros First macro: Sum all columns Second macro Paste values into a Copy row Deletes answer row (from first step)
Recording Macros Benefits Weaknesses Quick and easy way to add automated functionality to your spreadsheet. The macro recorder simply records the keystrokes that you take or mouse actions that you perform Code is guaranteed to be free from syntax/coding errors Can serve as a starting point if you are inexperienced. Weaknesses The macro recorder does not write the most efficient code. It records actions and commands you might not need or want. May have to record macro several times due to making errors in the recording process. More chances for making errors. If changes are made to the document (add column or row), the macro may not function as intended. Not as robust Works well for basic tasks, but sometimes you want advanced functionality that recorded macros can’t make possible (button tasks)
Performing Financial What-If Analyses You have a result value you are interested in. What happens to the result if an input value changes?
Goal Seek takes the opposite approach. In its most simple form, change the input value and observe the result. Goal Seek takes the opposite approach. Here is the answer I want. What must happen for that answer to be achieved? To perform Goal Seek: In the Data Tools group on the Data tab, click the What-If Analysis button, and then click Goal Seek In the Set cell box, select the result cell, and then, in the To value box, specify its value (goal) In the By changing cell box, specify the input cell Click the OK button. The value of the input cell changes to set the value of the result cell
What happens if I change units sold? Here is the answer/goal that I want. What must happen to achieve that result?
Data Tables A data table organizes the results of several what-if analyses within a single table Insert a formula that references the input cell in the upper-left cell of the table One variable data table: specify one input cell and one or more result cells Two variable data table: specify two input cells and one result cell. In the Data Tools group on the Data tab, click the What-If Analysis button, and then click Data Table
Scenarios and Scenario Manager At most, a data table can have only 2 input cells. If you have more input cells (or several results cells), you will need to create scenarios and use the scenario manager (located in the Data tab, What-If Analysis grouping Scenario Manager enables you to create as many scenarios as you want, easily switching between the different scenarios to display the results of several what-if analyses
You can even create a scenario pivot table report to display the results from each scenario