Function:
Function is a type of Procedure or Routine. In VBA, a Function is one which returns a Value or Object and a Procedure is which does the action but not return something.
Functions are of two types:
- Pre- defined
- User- defined
A Pre- defined function is a name of a set of instructions. You just need to use this function by its name. These functions are written in the libraries of the language so you don’t need to write the code for these functions.
A user- defined function is one which is user’s requirement specific. These type of functions need to be written by the user in the code window.
Pre- defined Functions in VBA:
In VBA, all pre- defined functions are categorized in 10 various categories
- String Functions
- Numeric/Mathematical Functions
- Logical Functions
- Information Functions
- Date & Time Functions
- Lookup / Reference Functions
- Data Type Conversion Functions
- File/Directory Functions
String Functions
STRCONV() | CURDIR() | CHAR() |
FORMAT() | LTRIM() | RTRIM() |
MID() | STR() | LCASE() |
TRIM() | LEN() | ASC() |
INSTR() | SPACE() | VAL() |
REPLACE() | LEFT() | RIGHT() |
UCASE() | INSTRREV() |
Numeric/ Mathematical Function
ABS() | FROMAT() | SGN() |
ATN() | INT() | SIN() |
COS() | LOG() | TAN() |
EXP() | RND() | FIX() |
ROUND() |
Logical Functions
CASE
IF-THEN-ELSE
Information Functions
ISDATE() | ISNULL() |
ISNUMERIC() | ISERROR() |
Date and Time Functions
DATE() | DAY(0 | NOW() |
DATEADD() | FORMAT() | TIMESERIAL() |
DATEDIFF() | HOUR() | TIMEVALUE() |
DATEPART() | MINUTE() | WEEKDAY() |
DATESERIAL() | MONTH() | WEEKDAYNAME() |
DATEVALUE() | MONTHNAME() | YEAR() |
Lookup and Reference Functions
CHOOSE ()
Data Type Conversion Functions
CBOOL() | CDBL() | CSNG() |
CBYTE() | CDEC() | CSTR() |
CCUR() | CINT() | CVAR() |
CDATE() | CLNG() | |
File/ Directory Functions
CHDIR() | DIR() | GETATTR() |
CHDRIVE() | FILEDATETIME() | MKDIR() |
CURDIR() | FILELEN() | SETATTR() |