1
2
I wanted to create a custom function that would be a shorthand for if(somefunction(arg)=something,"sometext",somefunction(arg))
So I don't have to duplicate somefunction(arg)
each time I do this, just like how iferror
lets us do away with if(iserror(somefunction(arg)),"sometext",somefunction(arg)
For example, I want to be able to type iftrue(somefunction(arg),"=A1","message")
and that to be equivalent to if(sumfunction(arg)=A1,"message",sumfunction(arg))
I tried:
Function iftrue(Fx, condition, show)
iftrue = Application.WorksheetFunction.if(Fx & condition, show, Fx)
End Function
But it gives #value.
To diagnose my problem, I tried some simpler functions, to see where I was going wrong. So I duplicated the SUM and If functions.
This "sum" function works.
Function testsum(a, b)
test = Application.WorksheetFunction.Sum(a, b)
End Function
But this "if" function doesn't work.
Function testif(a, b, c)
testif = Application.WorksheetFunction.if(a, b, c)
End Function
So I think my problem is the way I'm invoking the worksheet.function.if
.
I know I could just get around this by using VBA ifs instead but that's not really what I want to do.
please give an example of
iftrue
's parameters which you've tried and wasn't working. What doesn't work mean? Wrong output / error message? – Máté Juhász – 2016-10-21T13:07:43.427I had to do some parsing to deal with text. Please see my edit. It will work with formulas that return text as well as numbers, It will return a string. – Scott Craner – 2016-10-21T13:50:17.017
1It will now return the same as what the function returns. If the function returns a double so will this function. If it returns text so will this function. You may need to refresh the screen. – Scott Craner – 2016-10-21T13:57:42.403