How to Use an Excel VBA Function in a Cell

Written by jim campbell | 13/05/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.

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.