18. VBA Tips - Write Your Own Excel Function
Writing your own Excel function is remarkably easy as this tip will show you.
- You can write a function in VBA and use it on a worksheet
- The only thing you cannot do is to manipulate the workbook in any way
- Apart from that, user defined functions are simple to write and use
- So, if you think that Excel doesn't have the right function for you, write your own
Here's a screen shot of our user defined function in Excel:
Here's the code used:
Explanation
- In a new VBA code module, type: "Function myFunction" then hit ENTER
- VBA will then populate the entry and exit points of the function
- To get a return from a function, you set myFunction to equal something
- In this case: "Hello"
- In an Excel cell, type: =myFunction()
- This will return "Hello" to the cell
- A function can also take arguments and use those arguments inside
- Here's an example of that:
Training Video on how to Write Your Own Excel Function in Excel:
Attachment | Size |
---|---|
write-your-own-function.xls | 34.5 KB |
»
- Nick's blog
- Login or register to post comments
- 19689 reads
Recent comments
5 years 41 weeks ago
6 years 27 weeks ago
6 years 39 weeks ago
6 years 42 weeks ago
6 years 43 weeks ago
6 years 48 weeks ago
7 years 4 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago