I have a UDF that is a long if statement. Let's say my UDF based on the criteria I've set returns the contents of cell G2. Is there a formula (other then another long if statement) that will return H2 (1 cell over)?
I have a UDF that is a long if statement. Let's say my UDF based on the criteria I've set returns the contents of cell G2. Is there a formula (other then another long if statement) that will return H2 (1 cell over)?
Probably some more data is needed.
Are returned values located in one row or one column (one vector) in the sheet?
If so you could use formula
=index(thiscolumn,match(UDFresult,thiscolumn,0)+1) or =index(thisrow,1,match(UDFresult,thisrow,0)+1)
if this 1 cell over is alongside vector or if in perpendicular direction you could in similar way use OFFSET
or you could change your UDF to return already required cell
Best Regards,
Kaper
Impossible to say for sure without seeing the code in your UDF.
What is the return type of your UDF?
Note that these code samples are to illustrate the concept and I have not compiled or run them. If you provide your actual code then I would work with that.
One option is to have it return a Range instead of a value, then you can use OFFSET in the worksheet to return the value one cell over.
Then in your worksheet![]()
Please Login or Register to view this content.
=MyUDF(A1)
=OFFSET(MyUDF(A1),0,1)
Another option guaranteed to work in the general case is to write a second UDF that replicates the logic of the first but returns the next cell over. The way I would do this is to write a Private Function that returns the Range, then the UDF returns the value of that range, and your second UDF then returns the next cell over from that. This factors out the logic of the If statement into a single function, guaranteeing that the same logic is being used in both places.
Then in your worksheet![]()
Please Login or Register to view this content.
=MyUDF(A1)
=MyOtherUDF(A1)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks