DISCOVER
×

How to Use an Excel VBA Function in a Cell

Updated July 19, 2017

Visual Basic for Applications, or VBA, is a programming language used for Microsoft Office. You add VBA functions to Excel spreadsheet cells in order to automate calculations without requiring your readers to calculate numbers. VBA functions are added as modules; you insert a module using the VBA programming interface included with the Excel software. The modules require coding, so you must be familiar with the Visual Basic language.

Double-click the XLS file on your desktop to open the file and load the Excel spreadsheet software. You can also open Excel by clicking the Windows "Start" button and typing "Excel" in the search text box.

Click the cell you want to use for the VBA function. Click the "Insert" menu item and select "Module." This menu item opens a module window, which is a coding editor for Microsoft Office.

Type a name for your function. For instance, if you want to create a function that displays the current date, type "currentdate" as the VBA function name.

Type your function's code. You can create a small, one-line function, or write hundreds of lines of code to calculate the results. For instance, if you want to show the current date and time in the cell, type "Now."

Close the VBA module editor. The results of the function are shown in the Excel cell. If you've used the "Now" code, the cell will show the current date and time.

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Jim Campbell has been a computer engineer for over five years. He excels in hardware repair, computer programming and troubleshooting, and software design. He is currently attending Florida Atlantic University, pursuing a master's degree in computer and electrical engineering and fine-tuning his technical writing abilities.