Article ID: 161120 - View products that this article applies to.
This article was previously published under Q161120
For a Microsoft Excel 2002 version of this article, see 291309
For a Microsoft Excel 2000 version of this article, see 213765
You can call a built-in Microsoft Excel worksheet function directly from a Microsoft Visual Basic for Applications macro. This article describes how to use a built-in worksheet function in a macro.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. You can use a built-in worksheet function in a macro by calling the function as a method of the Application object (or the WorksheetFunction object in Microsoft Excel 97 or Microsoft Excel 98). For example, to successfully call the ACOS worksheet function in a version of Microsoft Excel listed at the beginning of this article, you can use the following line of code in a macro:
If you are using Microsoft Excel 97 or Microsoft Excel 98, use the following line of code:
NOTE: If you attempt to use a built-in worksheet function without qualifying it with the Application or WorksheetFunction object, you may receive the following error message:
You are not able to use all built-in worksheet functions with the Application or WorksheetFunction object. Visual Basic for Applications provides many functions that are equivalent to the built-in worksheet functions in Microsoft Excel. You cannot use a built-in worksheet functions for which there is an equivalent in Visual Basic with the Application or WorksheetFunction object.
Sub or Function Not Defined
For additional information about the worksheet functions that are not supported with the Application or WorksheetFunction objects, please see the following article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/107564/EN-US/ )XL: Not All Worksheet Functions Supported as Application
Microsoft Excel 97For more information about using Microsoft Excel Worksheet Functions in Visual Basic, click the Office Assistant in the Visual Basic Editor, type using built-in functions in a macro, click Search, and then click to view "Using Microsoft Excel Worksheet Functions in Visual Basic."
Microsoft Excel 7.0For a complete list of the worksheet functions that you can call with the Application object, type the following text
worksheet functions, usingand then double-click the selected text to go to the "List of Worksheet Functions Available to Visual Basic" topic.
Microsoft Excel 5.0For a complete list of the worksheet functions that can be called with the Application object, choose the Search button in Visual Basic Help, and type:
worksheet functionsChoose the Show Topics button, select the topic "Using Worksheet Functions in Visual Basic", and choose Go To.
Article ID: 161120 - Last Review: August 17, 2005 - Revision: 2.1
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Contact us for more help