Creating a Custom Excel Function

Though macros are an advanced topic, here's a good place to start
by Mark Henri
Use the macro editor to create a custom function. Here's how--
  1. Create a new Excel spreadsheet, name it and save it. Or you can open an existing spreadsheet.
  2. Choose Tools > Macros > Visual Basic Editor
  3. In the projects window, choose 'ThisWorkbook'.
  4. If you don't see a blank work area to the right, choose Insert > Module.
  5. Type in the following formula--
    function VanityAge(a)
       VanityAge = a - 5
    end function
    
  6. Switch back to the Excel window (Alt + Tab)
  7. Save the spreadsheet
  8. Type the following into cell A1 and press enter when done--
    =VanityAge(44)
    
  9. Hopefully you see the number 39 in the cell
  10. Put the value 50 in A3
  11. In cell A2, enter the following and press enter--
    =VanityAge(A3)
    
  12. A2 should now contain 45.
Click here to see an example workbook.




Send comments or concerns to