Making Excel Automatically Calculate 2 Out of 4 Values

  • Thread starter SherlockOhms
  • Start date
  • Tags
    Excel
In summary, the user needs to input values for R, Gamma, CV and CP in cells across the top of the sheet and then need to write formulas in other cells to calculate Cv and Cp.
  • #1
SherlockOhms
310
0
So, I'm a creating a spreadsheet which receives a number of inputs from the user and then does various calculations with these values.
The user need only input 2 out of the 4 inputs below and as you can see, with 2 values, the other 2 can be calculated. How do I make it so that excel does this automatically?

So, R = CP - CV (1)
Gamma = CP/CV(2)
CV = R/Gamma - 1 (3)
CP = R + CV (4)

I've inputted the above formulas into the relevant cells for R, Gamma, CV and CP (i.e. (1) into R's cell, (2) into Gamma's cell, (3) into CV's cell and (4) into CP's cell) but when I go and input R and Gamma, CV and CP aren't automatically calculated. I actually keep getting some error message about a circular reference.
 
Last edited:
Physics news on Phys.org
  • #2
You're either going to have to have some pretty involved formulas or you'll need to write some Excel Visual Basic for Applications (VBA) code to do this. I haven't thought about this very deeply, but here are my initial thoughts. Let's say you have four cells across the top for your input values.

On another row farther down, you have four more cells for the output values, preferably with some sort of labels next to them so the user can tell which is which.

The cells lower in the table would have formulas that either copy the value that's in the corresponding cell in the first row (assuming the user entered a value) or compute a value using two of the values in the first row.

As an example, if the user entered values for the first two cells in row 1, these values would be copied directly to the first two cells in the lower row. The other two values in the lower row would be calculated from the two entered values in the first row.

Your formulas or VBA would need to check which two cells in the first row are empty, and there are 6 ways this can happen; i.e. 1st & 2nd, 1st & 3rd, 1st & 4th, 2nd & 3rd, 2nd & 4th, 3rd & 4th.

I'm assuming that given any two of the values, the other two can be calculated with no other information needed. That might or might not be the case - I haven't done any checking.
This link applies to Excel 2010 VBA:
http://msdn.microsoft.com/en-us/library/ee814737(v=office.14).aspx
 
  • #3
I've never actually written any VBA. Could I implement this in excel just using a few IF statements and functions?
 
  • #4
Yes, I believe so.

Edit:
As a proof of concept, I put together a quick Excel sheet that uses the formula for power (watts), current (amps), and voltage (volts).

Across the top I have three input cells in which the user puts any two of the three values.

A few rows down I have three more cells for the computed values of power, current, and voltage. The formula for power looks like this:
Code:
=if(isblank(a2), b2*c2, a2)

The formula for current looks like this:
Code:
=if(isblank(b2), a2/c2, b2)

The formula for voltage looks like this:
Code:
=if(isblank(c2), a2/b2, c2)
 
Last edited:
  • #5
Maybe I'm missing something, but, if the user wants Cv and Cp from inputs R and Gamma, why not just use the last two equations (3) and (4).

Equation (4) is just a re-write of equation (1). Also, Equation (3) is just a re-write of equation (2) using equation (1) (I believe equation 3 is really Cv =R/(Gamma-1) )

Use two blank cells to hold inputs R and Gamma

Construct formulaes in two other cells to calculate Cv and Cp

Cv = R / (Gamma - 1)
Cp = R + Cv
 
  • #6
TheoMcCloskey said:
Maybe I'm missing something, but, if the user wants Cv and Cp from inputs R and Gamma, why not just use the last two equations (3) and (4).

Equation (4) is just a re-write of equation (1). Also, Equation (3) is just a re-write of equation (2) using equation (1) (I believe equation 3 is really Cv =R/(Gamma-1) )

Use two blank cells to hold inputs R and Gamma

Construct formulaes in two other cells to calculate Cv and Cp

Cv = R / (Gamma - 1)
Cp = R + Cv

I haven't played with these formulas at all, but the idea was that a user would enter any two of the quantities, not just R and Gamma.
 
  • #7
A slight generalisation of Mark's method would be to put the power, current and voltage in cells B2, C2 and D2 respectively. In cell A5 you write
Code:
=if(and(isblank(b2),not(isblank(c2)),not(isblank(d2))),1,0)
which returns 1 if and only if the user has filled in c2 and d2 but not b2. You put the other two permutations in A6 and A7. Then you populate cells B5:D7 with if statements that compute the correct answer if the corresponding cell in column A is 1, and return zero otherwise. So, for example, cell B5 would contain:
Code:
=if($a5=1,c2*d2,0)
You can get your final answers with sum(b5:b7), sum(c5:c7) and sum(d5:d7). If the user hasn't filled in two values, this sum is zero because all of the cells A5:A7 are zero. If the user has filled in two values, exactly one of the cells A5:A7 will be 1, and the corresponding cells in columns B, C and D will be non-zero. The sum of b5:b7 will be the correct answer plus zero plus zero.

I think this is an improvement over Mark's method (although it's overkill for Mark's example and arguably for yours) because it largely separates the "which maths should I use?" from actually doing the maths. The decision is in column A; the work is in columns B:D; a clever trick is used to gather up the final result.

Does this all make sense?
 
  • #8
Thanks for the reply. I'll read through that and get back to you later on when I get a chance.
 

1. How can I make Excel automatically calculate 2 out of 4 values?

To make Excel automatically calculate 2 out of 4 values, you can use the "IF" function. This function allows you to set a condition and specify what should be calculated if the condition is met. For example, you can set a condition to calculate the average of two values if both of those values are entered, and leave the other two blank. This way, Excel will automatically calculate the average of the two values you entered without affecting the other two values.

2. Can I use a formula to automatically calculate 2 out of 4 values in Excel?

Yes, you can use a formula to automatically calculate 2 out of 4 values in Excel. As mentioned before, the "IF" function is a useful tool for this. You can also use other functions such as "SUMIF" or "AVERAGEIF" to calculate specific values based on certain criteria.

3. How do I set up the "IF" function to calculate 2 out of 4 values?

To set up the "IF" function, you will need to specify the condition, the value to be calculated if the condition is met, and the value to be calculated if the condition is not met. For calculating 2 out of 4 values, you can use the condition "AND" to specify that both values need to be entered in order for the calculation to take place. You can also use the "ISBLANK" function to check if a cell is empty or not.

4. Is it possible to make Excel automatically calculate 2 out of 4 values without using a formula?

Yes, it is possible to make Excel automatically calculate 2 out of 4 values without using a formula. You can use the "Data Validation" feature to set up a rule for the cells that should only accept certain types of input. For example, you can set a rule to only allow numerical values in a cell, and then use the "Average" function to automatically calculate the average of the two values entered in that cell and another cell.

5. Can I use conditional formatting to automatically calculate 2 out of 4 values in Excel?

Yes, you can use conditional formatting to automatically calculate 2 out of 4 values in Excel. You can set up a conditional formatting rule that will apply a certain format to a cell if a condition is met. For example, you can use conditional formatting to highlight the cells where the average of two values is automatically calculated, making it easier to identify these values in your spreadsheet.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
0
Views
1K
Replies
0
Views
2K
Replies
2
Views
548
  • Introductory Physics Homework Help
Replies
2
Views
2K
  • Introductory Physics Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
1K
  • Advanced Physics Homework Help
Replies
4
Views
1K
  • General Math
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Replies
7
Views
2K
Back
Top