Function ="C+ number specified in cell A1) automation - excel

In a Google Sheet, I would like to enter a number in a cell and have certain functions in that sheet use that number.
So if cell "A1" has the value 2 assigned to it I want a function to use =C+(the value in cell A1), which is 2. So the function displays the value of C2. When changing the number in cell A1 to 5, my function should change to C5 as well . Any recommendations?

It seems to be the same as Excel. I tested it.
=INDIRECT("C" & VALUE(A1))
or
=INDIRECT("C"&A1) which is simpler (thanks Nirk)
Possible duplicate: Dynamic cell access

Related

Get Excel cell relative reference into a cell

I am trying to find how to get an excel formula to get a cell's relative reference into a cell.
A formula that would be like =getcellreference(B2) and then has B2 as the output.
Nothing complicated but i could not find a simple solution.
You can use CELL():
=CELL("address",B2)
For formatting to literally show B2 instead of the absolute reference, you can do:
=SUBSTITUTE(CELL("address",B2),"$","")
If all you are trying to do is output a cell reference that you manually input, then all you need to do is:
="B2"
or
B2 (no equals sign)
You can use the ADDRESS function to obtain the address of a cell in a worksheet, given specified row and column numbers
ADDRESS(row_num, column_num, [abs_num], [a1], [sheet_text])
So for cell B2, you will need to put =ADDRESS(2,2) where the first 2 stands for the row number and 2nd is for column B.

I am trying to use a cell text string as a cell reference

I would like to use the text contents of cell A1 , to change the cell references of a formula in A2.
That is, I want inputs to A1 (e.g. the number "4") to change the formula in A2 (which starts off as =SUM(B1:B4) to =SUM(B1:B8).
In sum, I would like the cell references in the formula of A2 to change according to the value in A1.
How can this be done?
In Excel, if you use the INDIRECT function, you can refer to another cell's value by using text provided to the function, so:-
=INDIRECT("B"&A4)
If A4 contained the value "2", then the function would refer to B2.
Hope that makes sense. Using this you can then hopefully get your formula to behave the way you want.
For more info try this
So, if the value you stick in A1 is something like "4" and then you want to change that to "8" and have it affect the range inside the first Sum (for instance) you could use =Indirect():
=SUM(Indirect("B1:B" & A1))

Comparing cells with using Excel LEFT Function

I wanted to compare value in cell A1 and B1.
However, sometimes PC give different value as cell B1.
Initial code I've been writing is as below in cell C1:
=IF(ISERROR(MATCH(A1,$B$1:$B$5,0)),"","Duplicate")
This code only compare exact value. Thus, I'm trying to add LEFT Function into function above:
=IF(ISERROR(MATCH(Left(A1,8),$B$1:$B$5,0)),"","Duplicate")
But above function only count character in A1 only. How do I add LEFT(B1,8) to also read value in cell B1?
Thanks.
Regards,
Zaiem
Maybe what you would like is:
=IF(MAX(IFERROR(FIND(LEFT(A$1,8),B$1:B$5),""))=1,"Duplicate","")
entered with Ctrl+Shift+Enter

Evaluating a formula defined in another cell

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

Excel - Sheet as a function

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.

Resources