Have a Question?

If you have any question you can ask below or enter what you are looking for!

Excel function that returns formula choice

I am trying to write an Excel VBA function that will return one of two input parameters as the formula for the cell it is input in based on a global setting somewhere else in the sheet. IE, somewhere else in the sheet someone sets A or B, then formulas that call the functon AorB will return A or B based on what the global setting is.

Function AOrB(A As Variant, B As Variant) As Variant
    If someSetting = A Then
        AOrB.formula = A
    ElseIf someSetting = B Then
        AOrB.formula = B
    End If
End Function

I've scrounged pretty heavily but I just don't have the knowledge of what types to input and return in order to allow the function to return.

Any help would be appreciated.

  Devbrat Tripathi

I am not sure why would you want to use a UDF or VBA solution for this scenario, knowing that we have excel built in functionalities to perform this operation.

You could either use Excel IF function or CHOOSE function to perform this operation provided the requirement is much more complex than it appears...

Appreciate if you could share a sample file along with the result required for us to assess the requirement and provide an efficient solution.

  Asheesh Mattoo       25 Feb 2017       1       0     

Post Your Answers:

Please use the CODE HIGHLIGHT Button to format/highlight your codes if any