Download the best tutorial, website and reference tool on Excel |
Lesson 6: VBA for Excel Code for Functions Three topics in this lesson: using Excel functions within macros, creating new Excel functions with VBA for Excel and then using VBA functions within macros. |
Existing Excel Functions
There are hundreds of functions
available in VBA. Most of the functions that you find in Excel are
available through macros in this form: |
New Excel Functions You can create new functions in Excel. For example the function created by the code below will simply multiply the value of a cell by 2. Function fctDouble(varInput) Once this code is in a module in your workbook you access the new function the same way that you access the other functions by clicking on the icon function on the tool bar or from the menu bar "Insert/Functions". In the dialog box select the "User Defined" category and select "fctDouble" and follow the instructions. |
VBA Functions Here are some VBA functions that I use within my Excel macros:
LCase, UCase
If
UCase(Selection.Value)= "TOTO" then...
NOW()
With the following code, the cell "A1" will carry the date
when the procedure is executed and will keep this value until you
execute the procedure again. It won't change every time you open the workbook. |
Download the best tutorial, website and reference tool on Excel |
All rights reserved PLI Consultant Inc.