VBA has got it is own set of functions which you can use in your code. You can extend this set of functions by using EXCEL built-in functions from within VBA. These functions will have the same syntax and parameters as in EXCEL itself. Here are some examples:
1. Sum a range of cells and put the result in VBA variable “Total”.
2. Count a range of cells and put the result in VBA variable “Count”.
3. Find the maximum value within a range of cells and put the result in VBA variable “Max”.
4. Use the Vlookup function to look for a value and return its corresponding match.
Vlookup will return a run time error if the lookup value is not found. To avoid this, enter the following statement somewhere before the VLookup statement:
This way you will not have an error message and no value will be returned from the function.
One more example. The code shown below checks to see if cell “B15″ is numeric. If it is numeric, it will convert its value to hex and put the result in “C15″. If not it will give an error message.
If WorksheetFunction.IsNumber(myRange) Then
c = WorksheetFunction.Dec2Hex(myRange)
Worksheets(“Sheet1″).Range(“C15″).Value = c
MsgBox “Invalid decimal value”