Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Go to view > macros > Record macto

The macro name can only be started with a letter/ special character The shortcut key gives a shortcut to run the macro. If a known shortcut (like v) is given, a shift is automatically added.

This shows that the macro is recording Once the macro records, anything being done in excel gets recorded. Once the work is complete, go to view again and stop the macro. Now remove the changes. If the macro is run again (either through the shortcut. Any changes done through the macro are unchangeable (undo doesnt work)

Alt + f8 opens the view macro dialogue box

Clicking on edit would open the editor window.

The left is the project explorer and right is the code window Macros begin with sub followed by name()

Comments with In the editor, f8 would run the code step by step Enable/Disable macros: File > Options > Trust Centre > Trust Centre Settings > Macros Save often used workbooks in the personalized macro workbook which creates a hidden personal excel. This would ensure the availability across workbooks and files Enable relative references. This takes note of the cell where initial starting was done and where work is done relative to the active cell. Now whenever the macro is run, the position of output is relative to the selected cell (uses offset function) Alt + f11 : Opens vba editor Excel codes can be run in immediate window. Formulas should be run using a ? before starting Range(cell number).select : selects a cell Sheetname.name = name : Naming a sheet Sheetname.activate : Select the worksheet Sheetname.delete Worksheets.add.name = name: create a new worksheet and select the name Range(cell start:cell finish).value = : to put value Range(cell start:cell finish).interior.color : Set color In trust centre, a location can be added as trusted location for macros Also, the developer ribbon, once checked shows the vba controls

For setting password to view macros Found in VB editor > Tools > VBA project properties

VB options, used to change the behavior of the editor

The same thing can be done when required variable declaration is checked Option explicit forces one to declare variables before being used

Static variables keep their value over multiple runs of the subroutine Reset button resets the value of static variable End keyword resets all static variables Variables can also be declared in global area (at top) to be accessible throughout all subroutines in the module. Declaration of variables in global area as public makes it accessible throughout all modules. Also in global, variables automatically behave as static (as they are not defined again and again) Escape characters work. Here its as expected Object browser (F2) contains all vba objects

You might also like