VBA Functions
On this page, you will find the most commonly used VBA functions explained with a simple example.
More VBA tutorials and tips are available in VBA Tips.
Arrays
Array | Returns an array containing the values passed as arguments. |
Choose | Returns a value from its list of arguments based on a number. |
Join | Groups the values of an array into a string, with or without a delimiter. |
Split | Divides a string based on a delimiter to obtain an array of values. |
UBound | Returns the highest index available for the specified dimension of an array. |
Dates and Times
CDate | Converts a value to a date. |
Date | Returns the current date. |
DateAdd | Adds the specified time interval to a date. |
DateDiff | Returns an integer corresponding to the number of specified time intervals between 2 dates. |
DatePart | Returns an integer corresponding to a data of a date. |
DateSerial | Returns a date based on a year, a month, and a day. |
DateValue | Converts a string to a date. |
Day | Returns an integer corresponding to the day of a date. |
Format | Returns a string according to a date or number in the specified format. |
Hour | Returns an integer corresponding to the hour of a date or time. |
IsDate | Returns True if the value is a date (or can be converted into a date) or False if it is not. |
Minute | Returns an integer corresponding to the minutes of a date or time. |
Month | Returns an integer corresponding to the month of a date. |
MonthName | Returns the name of the month based on the month number. |
Now | Returns the current date and time. |
Second | Returns an integer corresponding to the seconds of a date or time. |
Time | Returns the current system time. |
Timer | Returns the number of seconds elapsed since midnight. |
TimeSerial | Returns a time based on an hour, minutes, and seconds. |
TimeValue | Converts a string into time. |
Weekday | Returns the number of the day of the week based on a date. |
WeekdayName | Returns the name of the day based on the number of the day of the week. |
Year | Returns an integer corresponding to the year of a date. |
Dialog Boxes
InputBox | Displays a dialog box prompting the user to enter text. |
MsgBox | Displays a dialog box prompting the user to click on a button. |
Numbers and Math
Abs | Returns the absolute value of a number. |
CInt / CLng | Converts a numeric value to an integer by rounding to the nearest integer. |
CSng / CDbl | Converts a numeric value to a floating-point number. |
Int / Fix | Returns the integer part of a number. |
RGB | Returns an integer corresponding to a color in RGB format. |
Rnd | Returns a random number less than 1 and greater than or equal to 0. |
Round | Rounds a number according to the specified number of decimals. |
Val | Returns the numbers contained in a string. |
Tests and Conditions
IIf | Returns one of the 2 values passed as an argument depending on a condition. |
IsArray | Returns True if the variable points to an array or False if it does not. |
IsDate | Returns True if the value is a date (or can be converted to a date) or False if it is not. |
IsEmpty | Returns False if the variable has been initialized or True if it has not. |
IsMissing | Returns False if the optional argument has been filled in or True if it has not. |
IsNumeric | Returns True if the value can be considered a number or False if it can not. |
Switch | Returns the value corresponding to the first expression that returns True. |
VarType | Returns an integer corresponding to the type of the variable. |
Text
Asc | Returns the integer corresponding to a character. |
Chr | Returns the character corresponding to the integer argument. |
Format | Returns a string according to a date or number in the specified format. |
InStr | Returns an integer corresponding to the position of a value in a string. |
InStrRev | Returns an integer corresponding to the position of a value in a string starting from the right. |
LCase | Converts a string to lowercase. |
Left | Returns the specified number of characters from a string from the left. |
Len | Returns the number of characters in a string. |
Mid | Returns the specified number of characters from a string starting from the defined character number. |
Replace | Returns a string after replacing the substring(s) matching the searched value. |
Right | Returns the specified number of characters from a string from the right. |
StrReverse | Returns a string after reversing the order of the characters. |
Trim | Returns a string after removing the spaces at the left and right of the string. |
UCase | Converts a string to uppercase. |