-1

I'm trying to make an Excel sheet where people can easily change the formulas in multiple column. Viewers will have varying degrees of Excel experience.

Goals

  1. Users can adjust how columns are calculated
  2. Users can adjust how columns are calculated without directly editing every cell in the column or knowing excel syntax
  3. When needed, users can easily edit cells using Excel syntax (don't need to parse multiple levels of IF statements).

Potential Methods

  1. All possible formulas are in every column cell, with IF statements. The simplest way is to put IF statements in the formulas, which reference option cells (e.g. Enter 1 to calculate a sum, 2 to calculate a product). However, once there are multiple parameters like these, the formulas in each cell become very complicated and difficult for a new viewer to edit.
  2. Like above, but put formulas in separate cells using EVALUATE. E.g. If option 1 is selected, calculated cell references formula in A1; if option 2 is selected, calculated cell references formula in A2. In this option the formulas are easily editable. However, EVALUATE is not available in current versions of Excel for Mac, and some users will be on Mac.

Example

In the table below, c = a + b

C is sum?       1
C is product?   0

a   b   c
1   2   3
4   5   9
2   2   4
5   3   8
6   1   7

I'd like users to easily change column c to c = a * b

C is sum?       0
C is product?   1

a   b   c
1   2   2
4   5  20
2   2   4
5   3  15
6   1   6

I don't know VBA but welcome VBA answers.

5
  • Do you only need two calculations? That is, either SUM or PRODUCT? If so, this works: =IF($G$2=1,SUM(A2:B2),PRODUCT(A2:B2)) where G2 value of 1 is for SUM.
    – Isolated
    Commented Feb 22, 2021 at 22:18
  • Unfortunately the real case is much more complicated. My current approach, though, has been to do what you have here. Would be nice to have something cleaner but that might not exist!
    – Unrelated
    Commented Feb 22, 2021 at 22:28
  • @Isolated oops forgot to mention you and don't have the rep to edit comments
    – Unrelated
    Commented Feb 22, 2021 at 22:38
  • 1
    I think it's going to be hard to get an answer unless more specifics are provided. Nested IFS would be easy if the operator is changing to one of several values. But if it's much more complicated, then data and desired output would be helpful.
    – Isolated
    Commented Feb 22, 2021 at 22:46
  • A sheet that is simple on its face has necessarily made strong assumptions about the way it will be interacted with and has a lot of complexity underneath doing all of the heavy lifting. You should start to learn VBA, like I did when I first started playing with macros to make a complex task simpler and faster, by recording macros of the basic steps of what you envision, and then working your way up to more complex and holistic tools that solve the entire problem. Commented Feb 23, 2021 at 2:30

1 Answer 1

1

You could use the following (nice to find a worthwhile, not forced, use for SWITCH(), finally):

=SWITCH($E$1,"Sum",A2+B2,"Product",A2*B2)

You'd take their input about what to do in cell E1. What would really make it work nicely would be a Data Validation rule for E1. I used a List with the options Sum,Product. Must remember those double quotes around the options inside SWITCH().

Another approach could use LET():

=LET(Sum,A2+B2,Product,A2*B2,IF($E$1="Sum",Sum,Product))

Of course, there's the old EVALUATE() using a variety of methods to get the formula parts. One is to use a VLOOKUP() which returns complete formulas to EVALUATE(). Could combine that for the large structure if more complicated formulas are desired, with either of the above for the minor details inside them, like ranges. You are clearly aware of EVALUATE() and how to use it, generally, so it would just take the cell-side work, creating the lookup table and figuring out what smaller elements you want to use the above thoughts for.

Not the answer you're looking for? Browse other questions tagged .