Using Built-in Functions
VBA comes with a large number of built-in functions that perform commonly needed operations - everything from determining whether a file exists to returning the current date and converting data from one format to another. (For example, you can use a function to convert numeric data into a text string.)
This tutorial demonstrates what functions are, what they do, and how to use them. Along the way, you'll meet some of the key functions built into VBA - including functions that convert data from one data type to another, functions that manage file operations, functions that do math, and many others.
You can also create custom functions of your own to supplement VBA's built-in functions.
In this tutorial you will learn to do the following:
- Understand what functions are and what they do
- Use functions
- Use key VBA functions
- Convert data from one type to another
- Manipulate strings and dates
In this tutorial:
- What Is a Function?
- Passing Arguments to a Function
- Using Functions to Convert Data from One Type to Another
- Using the Asc Function to Return a Character Code
- Using the Str Function to Convert a Value to a String
- Using the Format Function to Format an Expression
- Using the Chr Function and Constants to Enter Special Characters in a String
- Using Functions to Manipulate Strings
- Using InStr and InStrRev to Find a String within Another String
- Using LTrim, RTrim, and Trim to Trim Spaces from a String
- Using Len to Check the Length of a String
- Using the StrComp Function to Compare Apples to Apples
- Using VBA's Mathematical Functions
- Excel VBA's Date and Time Functions
- Using the DateDiff Function to Return an Interval
- Using File-Management Functions