Hi all
Hope for help here
Situation:
I am trying to use a different formula in Cell A depending on multiple variables in Cell B, C (possible will grow in the future and more variables will be introduced - but as of right now, it is only 2. But it is the reason I do not want to solve this with a nested IF).
So far I was not able to solve this problem.
The following was my approach:
Create a UDF named FormulaValue
In the Function use a Select Case checking on the variable combination of cells B, C
Values for B and C can be either 'selection' or 'no selection' as it is 2 variable right now, there are 4 possible combinations.
[/I]
The result when adding this UDF in excel is #Value. Clicking on the function to see what happens shows that Inputfield is one of the Select cases, but then no result is provided.
Thanks for your feedback.
Regards Marco
Hope for help here
Situation:
I am trying to use a different formula in Cell A depending on multiple variables in Cell B, C (possible will grow in the future and more variables will be introduced - but as of right now, it is only 2. But it is the reason I do not want to solve this with a nested IF).
So far I was not able to solve this problem.
The following was my approach:
Create a UDF named FormulaValue
In the Function use a Select Case checking on the variable combination of cells B, C
Values for B and C can be either 'selection' or 'no selection' as it is 2 variable right now, there are 4 possible combinations.
VBA Code:
[I]Function FormulaValue(Inputfield)
Select Case Inputfield
Case Is = "no selection|no selection"
FormulaValue = "=SUMIFS(data!G:G,data!H:H," >= "&DATE($D$6,$E$6,$F$6),data!H:H," <= "&DATE($G$6,$H$6,$I$6),data!BT:BT,'Results'!C24)"
Case Is = "selection|no selection"
FormulaValue = "=SUMIFS(data!G:G,data!H:H," >= "&DATE($D$6,$E$6,$F$6),data!H:H," <= "&DATE($G$6,$H$6,$I$6),data!BT:BT,'Results'!C23,data!BR:BR,'Results'!$N$4)"
Case Is = "no selection|selection"
FormulaValue = "=SUMIFS(data!G:G,data!H:H," >= "&DATE($D$6,$E$6,$F$6),data!H:H," <= "&DATE($G$6,$H$6,$I$6),data!BT:BT,'Results'!C23,data!BY:BY,'Results'!$O$4)"
Case Is = "selection|selection"
FormulaValue = "=SUMIFS(data!G:G,data!H:H," >= "&DATE($D$6,$E$6,$F$6),data!H:H," <= "&DATE($G$6,$H$6,$I$6),data!BT:BT,'Results'!C23,data!BY:BY,'Results'!$O$4,data!BR:BR,'Results'!$N$4)"
End Select
End Function
The result when adding this UDF in excel is #Value. Clicking on the function to see what happens shows that Inputfield is one of the Select cases, but then no result is provided.
Thanks for your feedback.
Regards Marco