Vba (Visual Basic For Applications) : Notification Also Check Trust Access To The VBA Project Object Model OK OK
VBA (VISUAL BASIC FOR APPLICATIONS)
Anything created in VB will be known as MACROS or MINI PROGRAM.
VBA is used to create Automated tasks.
ADVANTAGES: Consistent, Faster, Lesser Error, Beyound Excel, You r not needed.
DISADVANTAGERS: You have to know VBA, Excel, It could Crash.
VBA IS CREATED→ Stores code in module→ procedures→ Functions→ objects.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
82 views
Vba (Visual Basic For Applications) : Notification Also Check Trust Access To The VBA Project Object Model OK OK
VBA (VISUAL BASIC FOR APPLICATIONS)
Anything created in VB will be known as MACROS or MINI PROGRAM.
VBA is used to create Automated tasks.
ADVANTAGES: Consistent, Faster, Lesser Error, Beyound Excel, You r not needed.
DISADVANTAGERS: You have to know VBA, Excel, It could Crash.
VBA IS CREATED→ Stores code in module→ procedures→ Functions→ objects.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14
VBA (VISUAL BASIC FOR APPLICATIONS)
Anything created in VB will be known as MACROS or MINI PROGRAM.
VBA is used to create Automated tasks. ADVANTAGES: Consistent, Faster, Lesser Error, Beyound Excel, You r not needed. DISADVANTAGERS: You have to know VBA, Excel, It could Crash. VBA IS CREATED Stores code in module procedures Functions objects. WELCOME TO VBA WORLD. VBA Security Settings. To create Macros we need to develop a Ribbon by right click on ribbon Customize ribbon (Check developer).
01 RECORDING MACROS. (From FIGURE: ABC), Make sure Use Relative Reference is highlighted as shown in figure. TO RECORD MACROS: (FROM FIGURE: ABC): Goto
Fill as shown in figure. The recording starts.
CAUTIONS: After the above step Macros is now started. So be aware not to make any mistake while making a Macros. Type any thing in a cell make necessary adjustments (As written in cell A1 and A2)
To check ur own security settings. Goto file trust center trust center setting macros setting disable All Macros With Notification also check Trust Access To The VBA Project Object Model OK OK When job done then click in any other cell (From Above Figure, In Cell C1 and C2), (as we set a shortcut Key in the Record Macro Dialog Box). Press your shortcut i.e. CTRL+SHIFT+G, it will display your written word in that cell. EDITING ANY CREATED MACROS.
(FROM FIGURE ABC) Click
In a new Excel Worksheet when you create a MACROS. To save this MACROS press CRTL+S, and follow the steps. 1. Give any name to file 2. Select File Type as: Excel Macro-Enabled WorkBook 3. Save.
CAUTION: DONOT SAVE A MACROS FILE IN ANY OTHER FILE TYPE, BECAUSE THE MACROS IN THE FILE WILL NOT WORK. CREATING MACROS IN VBA. 1. Project window help us to go through different sheets. 2. Code area is used to type codes and commands in VBA. Or it shows the codes and commands of a Macros in VBA. 3. Module saves all the codes and commands inside. 4. Immediate window is use to run the codes in other word it is used to apply early check to a VBA written Module
CREATING VBA MODULE:
when Required variable is marked check after that if you open a new module it will display ( OPTION EXPLICIT). Which means every variable used in code window should be defined perfectly. CREATING A SUB PROCEDURE MANUALLY SUB PROCEDURE: Set of code which are when required can be executed i.e. like a command or set of instructions. MACROS can be created by recording Macros or by manually through VBA. 1. From a new excel sheet 2. Goto Developer VISUAL BASIC 3. Insert Module from INSERT. 4. In Code Window type: sub sample () press enter. 5. 6. Type msgbox
CREATING A FUNCTION PROCEDURE: FUNCITON PROCEDURE: it is a function (NOT A SUB OR SUB PROCEDURE) which can be used as a formula Creating a function. 1. open new Excel Worksheet. 2. Goto Developers Visual Basic Insert new module. USING COMMENTS WITHIN YOUR VBA CODE:
DECLEARING VARIABLES AND DATA TYPE.
SCOPE OF A VARIABLE A fish live in water and dies on land The scope of variable is defined as where the variable is declared i.e. with the Option Explicit or after the Procedure (sub procedure or Function procedure) or what type of Variable is used and where used and why used.
STATIC VARIABLE DECLARETION Static variable declaration is explained as; if x = x + 1 then when the test run for 1 st time it will give output 1. For 2 nd time when the test run it will give output 2, and again the the run it will give 3, 4, 5, 6, ... Respectively. But if the test is run in Dim variable declaration for same equation, everytime it will give output as 1 and only 1.
CONSTANT VARIABLE DECLARATION. If a value in a Procedure is always constant (i.e. x^2). The constant value (2) should be Declared as a Constant (i.e. Const power2 As integer = 2), power2 is the name of the Constant and As integer = 2 is the limitation of the constant value.
INTRINSIC CONSTANT Intrinsic Constant are the universal constant values used for specific Color, unit, thing etc.
STRING AND DATE TYPE Type of data consist of 20 billion words which can be limited String are of two types; 1. Variable String 2. Fixed length String In excel VBA we can use dates b/w January 1 st of 100 to the December 31 of 9999. VBA OPERATORS: VBA Operators are () BRACKETS + ADDITION * MULTIPLICATION / DIVISION - SUBTRACTION ^ EXPONENTIAL & CONCATENATION \ INTEGER DIVISION MOD REMAINDER OF A DIVISION OPERATION = ASSIGNMENT OPERATOR ARAYS Array is a group of variables, all have same data type, and all have the same name Effectively you declare a variable as an array and within it you can a have a number of indexes or number of pockets. If you think such as the months of the year, there are 12 months of a year, we can create instead of 12 variables we create one variable called month name and within ti we have 12 pockets. HOW TO DECLARE A ARRAY IN VBA.
How to declare 2D arrays in VBA:
How to declare 3D arrays
How to create a Dynamic Array in VBA
CHAPTER 5 501REFERENCING CELL USING RANGE OBJECT Range object will allow as to select ranges and manipulate their values or their properties. Range is a built-in object within VBA. As it is a built-in object therefore it will have a set of properties we can explore and set of methods that can allow us to work with the object. It can be used as shown in figure below:
502THE CELLS PROPERTY: When referring to the ranges within the VBA we will tend to use the cell property. The reason for this is allow you to reference a row and a column by a numeric value, because as using the numeric value we can programmatically can define those values, which allows us much more flexibility than using A1, A8, J45, C6, H12, O6. SEE EXAMPLE BELOW.
503THE OFFSET PROPERTY: Offset property allows us to reference cells that are offsets from the range that you are referring to: Range object that refer on a sheet, (F5) we can refer than to a different cell by using the offset property Offset Property is based on two values ( RowOffset, Columnoffset) row offset refers to the No. of rows to your off set, (FROM F5: if we want to go to the upper rows than we use +ive values [1, 2, 3, 4,] or want to go down use _ive values [-1, -2, -3, -4, ], or if offset the same row use [0] for row reference. Vise versa. 504THE VALUE OF THE RANGES: The value of the range gives value to your desired or created range within the sheet, worksheets of the same workbook, worksheets of the different workbooks.