Question:
I need help writing a custom function for Microsoft Excel 2003, in Visual Basic.?
ut_oskie
2006-11-29 09:08:15 UTC
I need a to write a custom function for something that I am going to use almost every day, but I have never used Visual Basic and I need to know how to write it. The formula in excel is:
=IF((ISBLANK(C3)),B2,C3).
I entered the formula into cell B3. The cell references are relative; I included the numbers for their orientation.
Three answers:
Mihai L
2006-11-29 16:40:07 UTC
This function I've wrote takes the right cell as argument, and, if that cell is not empty, returns it's value , otherwise the value of the cell above the cell where the function resides:



Function MyFunction(rightcell As Range)

Application.Volatile True

MyFunction = IIf (rightcell (1, 1).Value <> "", rightcell (1, 1).Value, rightcell(1, 1).Offset(-1, -1).Value)

End Function



To make the function available proceed as following:

-Press Alt+F11- this will bring up the VBA editor

-navigate to Insert > Module to open a blank module screen

-paste the above code there

-close the VBA editor



As in your example,in B3 cell, you will call te function like this:

=MyFunction(C3)
SmartSpider
2006-11-29 10:14:57 UTC
Adding more description about what you are trying to achieve would be useful in helping you. Do you want to write a VBA function that uses this formula to calculate values for certain cells? Try giving and example of what you are trying to get at... and if it requires looking at the data, email me your workbook with details of what you are trying to do at your_taurean@yahoo.com :)



I should be able to help.



.
?
2016-05-23 06:04:48 UTC
In your excelsheet, choose the cell you wish the result in. After doing this, trace your mouse to the long bar on top of the sheet, that looks like an address bar. There you will see a sign that resembles an 'fx'. Click on it, choose your desired function, select your cells and you're ready to go! Enjoy!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...