Is it possible to reference text from various cells to construct a formula in a different cell?
Example:
A1 = 1
A2 = >
A3 = 0
=IF(CONCATENATE(A1:A3),1,0) returns 1
This obviously returns an error, but I'm hoping there's a function that does something like this.
Also I'd like to avoid using if statements since I have quite a few values that can populate the reference cells. (EX: IF(A2="<",...,IF(A2=">",...)))
Related
Ok, so I am trying to do something I thought was very simple, but it is turning out to be more complicated.
What I am trying to do:
Take a value through an if statement and return 1 or 0. But I want to be able to change the formula by changing values in cells and not editing the formula itself.
Example:
cell A1 = 41%
cell B1 = >
cell C1 = 40%
cell D1 = Formula with calculation
I want to create a formula that will tell me if that 41% is > than 40%, but if I change that > in B1 for a < (in a separate cell outside the cell with the formula) or I change C1 I want it to recalculate.
I have tried the following:
=IF(A1&B1&C1,1,0)
=IF(A1&INDIRECT(B1)&C1,1,0)
=IF(INDIRECT(A1)&INDIRECT(B1)&INDIRECT(C1),1,0)
all of these result in errors and I cannot figure out how to make it work. I am assuming it is taking the > and making it a string instead of a part of the formula.
Thanks for the help.
=COUNTIF( A1, B1&C1 )
... seems to do the trick, although converting C1 to text may give some rounding errors
An alternative would of course be to enumerate all the operations:
=--IFS( B1=">", A1>C1, B1="<", A1<C1 )
And add other operators as you come across them (NB the -- turns TRUE/FALSE into 1/0)
Use formula to sum cells which is reference of another cell
My requirement:
Note: Inside bracket is the formula that particular cell holds
A1(=Sheet1!A1) ==> 6
A2(=Sheet1A2) ==> 2
A3(=Sheet1!A3) ==> 2
A4 (=SUM(A1:A3)) ==> 0 (is what I am getting) but I need A4=10
Help me out with this.
As mentioned by #Scott, one of your cells probably contains a number stored as text.
To check try either selecting all the cells and setting the format or troubleshoot which cell(s) is(are) causing the problem.
=SUM(VALUE(A1),VALUE(A2),VALUE(A3))
This will convert each cell to a numeric value. If that works then start swapping out the value function for just the cell reference (e.g. -Value(A1) becomes simply A1) and see which cell breaks the sum function. Once you find that cell you can wrap whatever formula is in that cell in the value function to force it to store the numeric value.
I'm looking for a way to unpack an excel formula into a formula that depends only cells that don't refer to other cells.
Example: in the spreadsheet below, cell A1 contains the formula "B1 + B2". Meanwhile, cell B1 contains the formula "C1 + D1", while B2 contains the formula "C2 + D2". Cells C1, C2, D1 and D2 are all constants (in this case, the values 1, 2, 3 and 4).
What I want: I'm looking for a way (either already built into excel, or a user-defined function in VBA), that would function like this:
Call: =ExplodeFormula(A1)
Returns: "C1 + D1 + C2 + D2"
Any chance someone can help me out here? Thanks!
(Edit) A few things I think will be needed for this:
Some way to distinguish a cell reference in a formula from the functions used in that formula.
Some way to distinguish a range reference from a single cell reference (if a cell is referring to a range, like it would in the case of a vlookup, I'd be fine stopping at that level.
A way to iterate through the portions of the formula identified in parts 1 and 2 and break them down into simpler chunks that are recursively run through the same process.
You would have to build an Excel formula parser and apply it recursively to the formulas referred to by any references found in the original formula. And watch out for circular and repeated references!
There are a few formula parsers around, see for starters:
http://ewbi.blogs.com/develops/popular/excelformulaparsing.html
and as a matter of curiosity: why would you want to do this?
Say I've got a function name in cell A1, like SUM, and some data in B1 and C1. Is there any way to define a formula in one cell such that it calls the formula that is defined in A1 and have it work on B1 and C1 as data?
So something like:
=A1(B1:C1) should be equal to =SUM(B1:C1) since A1 contains the word SUM in it.
Essentially, something like preprocessor macros in C, or function pointers maybe.
You could do it using vba by creating a user defined function in a module:
Public Function applyFunction(functionName As Range, argument As Range) As Variant
applyFunction = Evaluate(functionName & "(" & argument.Address & ")")
End Function
If you put SUM in A1, and 1, 2, 3 in B1, B2, B3, =applyFunction(A1,B1:B3) will return 6. It is equivalent to calling =SUM(B1:B3).
EDIT
If you really don't want to use VBA, you can create a name (insert name in excel 2003 I think, Define Name in Excel 2010):
Define a new name (let's say eval1)
in the refers to area, enter =EVALUATE(A1&"(B1:B3)"), where A1 contains SUM and B1:B3 is the range with the numbers
in a blank cell, type =eval1 and it should return the result
But this approach is less flexible.
If you want to use a formula instead, you could possibly use the SUBTOTAL() function. However, it is a little limited.
Check out the image. It uses the reference to the function number for subtotal. You can expand this by creating a vlookup function if you want to use the name of the function, but you also have to provide a way to determine to use the regular function num or the 101-type values which ignores hidden values in the data range.
Check out this link for more info:
http://office.microsoft.com/en-us/excel-help/subtotal-function-HP010062463.aspx
I have two excel sheets. The first contains a formula for calculation with one input cell (A1), and one output cell (B1). The formula for B1 could be B1 = A1 * 3 (example).
The second sheet contains various values in column A: A1 = 4; A2 = 9; A3 = 5 ... In corresponding column B of this sheet I'd like to get the result of B1 (first sheet) = A1 (second sheet) * 3 for each A (second sheet) input value.
Basically I'd like to treat the first sheet as a function, where A1 is the argument and B1 the result that is passed back to the second sheet's B column.
Sheet 2
A1 4 B1 12 (result from sheet 1)
A2 9 B2 27 (result from sheet 1)
...
Is it possible without macros?
This is built into Excel. In version 2003, use the Data, Table menu.
You can find many examples on the net. Here is one.
You can create such tables with either 1 or 2 entries (parameters).
I don't think so .....
If in B1 Sheet1 you have
3*A1
If you try this in Sheet2 B1
`=SUBSTITUTE(Sheet1!$B$1,"A1",A1)`
it will give
3*4, and Sheet2 B2 will be
3*9etc
But I don't see how you could coerce this to a numberic calculation with formulae without possibly some heavy duty formula string parsing to separate numbers from operators (which is unlikley to flex as desired if you change the entry in B1 Sheet 1)
[Update 2: but fwiw I have done it with a named range]
I used this range name
RngTest
=EVALUATE(3*INDIRECT("rc[-1]",FALSE))
This is a global range name so it will work on any sheet, more powerful than my prior OFFSET effort. It multiplies the cell to the immediate left by 3
so entering =RngTest in B1:B3 (and then in this new example C1:C3 as well)
gives the output you want
I think you want to use this in your sheet two column.
Sheet1!B1 * Sheet2!A1
Entirely without VBA: expect lots of pain, I won't go there. But...
To substantially reduce the amount of pain, you could actually use this one tiny VBA user-defined function (not technically a "macro"), basically just a wrapper to make VBA's Evaluate function available in worksheet formulas:
Function eval(myFormula As String)
eval = Application.Evaluate(myFormula)
End Function
You could then use it like this in cell B1 on sheet 2:
=eval(SUBSTITUTE(Sheet1!$B$1,"A1","A"&ROW()))
Note that this requires Sheet 1 cell B1 to contain A1*3 and not =A1*3, i.e. no equal sign. Maybe with a bit more fiddling around, it can be made to work even with the = sign there...
EDIT: Actually, if you format Sheet 1 cell B1 as Text before typing in the formula, this will work even if your formula starts with a =.
Is it possible without macros?
Yes!
You can now use =LAMBDA for this.
Define your function using the name manager, then reference it in your second sheet's formula.
See syntax at Introducing the LAMBDA function.
For more information about how to use the LAMBDA function, see the support documentation.