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

ArrayReturns an array containing the values passed as arguments.
ChooseReturns a value from its list of arguments based on a number.
JoinGroups the values of an array into a string, with or without a delimiter.
SplitDivides a string based on a delimiter to obtain an array of values.
UBoundReturns the highest index available for the specified dimension of an array.

Dates and Times

CDateConverts a value to a date.
DateReturns the current date.
DateAddAdds the specified time interval to a date.
DateDiffReturns an integer corresponding to the number of specified time intervals between 2 dates.
DatePartReturns an integer corresponding to a data of a date.
DateSerialReturns a date based on a year, a month, and a day.
DateValueConverts a string to a date.
DayReturns an integer corresponding to the day of a date.
FormatReturns a string according to a date or number in the specified format.
HourReturns an integer corresponding to the hour of a date or time.
IsDateReturns True if the value is a date (or can be converted into a date) or False if it is not.
MinuteReturns an integer corresponding to the minutes of a date or time.
MonthReturns an integer corresponding to the month of a date.
MonthNameReturns the name of the month based on the month number.
NowReturns the current date and time.
SecondReturns an integer corresponding to the seconds of a date or time.
TimeReturns the current system time.
TimerReturns the number of seconds elapsed since midnight.
TimeSerialReturns a time based on an hour, minutes, and seconds.
TimeValueConverts a string into time.
WeekdayReturns the number of the day of the week based on a date.
WeekdayNameReturns the name of the day based on the number of the day of the week.
YearReturns an integer corresponding to the year of a date.

Dialog Boxes

InputBoxDisplays a dialog box prompting the user to enter text.
MsgBoxDisplays a dialog box prompting the user to click on a button.

Numbers and Math

AbsReturns the absolute value of a number.
CInt / CLngConverts a numeric value to an integer by rounding to the nearest integer.
CSng / CDblConverts a numeric value to a floating-point number.
Int / FixReturns the integer part of a number.
RGBReturns an integer corresponding to a color in RGB format.
RndReturns a random number less than 1 and greater than or equal to 0.
RoundRounds a number according to the specified number of decimals.
ValReturns the numbers contained in a string.

Tests and Conditions

IIfReturns one of the 2 values passed as an argument depending on a condition.
IsArrayReturns True if the variable points to an array or False if it does not.
IsDateReturns True if the value is a date (or can be converted to a date) or False if it is not.
IsEmptyReturns False if the variable has been initialized or True if it has not.
IsMissingReturns False if the optional argument has been filled in or True if it has not.
IsNumericReturns True if the value can be considered a number or False if it can not.
SwitchReturns the value corresponding to the first expression that returns True.
VarTypeReturns an integer corresponding to the type of the variable.

Text

AscReturns the integer corresponding to a character.
ChrReturns the character corresponding to the integer argument.
FormatReturns a string according to a date or number in the specified format.
InStrReturns an integer corresponding to the position of a value in a string.
InStrRevReturns an integer corresponding to the position of a value in a string starting from the right.
LCaseConverts a string to lowercase.
LeftReturns the specified number of characters from a string from the left.
LenReturns the number of characters in a string.
MidReturns the specified number of characters from a string starting from the defined character number.
ReplaceReturns a string after replacing the substring(s) matching the searched value.
RightReturns the specified number of characters from a string from the right.
StrReverseReturns a string after reversing the order of the characters.
TrimReturns a string after removing the spaces at the left and right of the string.
UCaseConverts a string to uppercase.