I am trying to create a conditional format formula to colour a cell based on the value of itself, the cell next to it on the right, and whether the cell on the first row in the same column is a weekday or not.
Currently it works correctly as follows:
=AND($A$2=0,$B$2=0,WEEKDAY($A$1)<>1,WEEKDAY($A$1)<>7)
I have a lot of cells I'd like to use this formula in, so I thought about creating a cover-all formula that used the ADDRESS function.
My original idea was to use:
=AND((ADDRESS(ROW(), COLUMN()))=0,$B$2=0,WEEKDAY($A$1)<>1,WEEKDAY($A$1)<>7)
(I've changed just one cell reference here for example, but I'd like to change all 4 if possible).
However, when I try to use ADDRESS(ROW(), COLUMN()) in place of an absolute cell reference, the formula doesn't format the cell anymore.
Is there a way to make this cover-all formula work so that I don't have to go through and change the referenced cell values each time for every cell? Am I missing something about the syntax? Or will this simply not work the way I'd like it to? Thanks in advance!
ADDRESS returns a string that looks like a cell address and "$A$2"<>0.Wrap the ADDRESS in INDIRECT or rewrite your original without absolute rows.
=AND(indirect(ADDRESS(ROW(), COLUMN()))=0, indirect(ADDRESS(ROW(), COLUMN()+1))=0, WEEKDAY($A$1)<>1, WEEKDAY($A$1)<>7)
=AND($A2=0, $B2=0, WEEKDAY($A$1, 2)<6)
I want to increment numbers starting from Zero in any cell without specific reference in Excel without VBA. I know to use col()-col($A$1), or a helper column, a1+1, auto-fill options. They all require a reference cell which much be changed if the starting cell is changed. but I have many offset formulae which reference the same ranges but from different cells.
Essentially what I've been unsuccessfully trying to do is have the one formula to paste into any cell, named range or other formula to increment by 1 starting from zero in any cell.
I don't think it should be hard to to, but so far my search has not yielded desired results as per my requirements.(As a last resort - after looking through all the aisles 4 times in every supermarket, twice) I'm asking the question.
What I want is:
0
1
2
3
4...etc. with rows or columns. in any cell without having to reference a absolute cell because I'll have to keep changing that reference with every formula in a different cell.
OFFSET(payments!$E$14,,GCD((COLUMN()-COLUMN('error test'!$B$1))*5),COUNTA(OFFSET(payments!$E$14:$E$522,,GCD((COLUMN()-COLUMN('error test'!$B$1))*5))),1)
(COLUMN()-COLUMN('error test'!$B$1) - this part is just to start at 0 but I have to keep changing the reference $B$1 whenever i put the formula into a different cell or table or pull data from another range. I have many like this, each one has to be carefully examine and changed accordingly to make sure the reference is correct.
Once I added an extra column to my data table, I had to go through every cell and every formula, name ranges, conditional formatting, and change the reference.
Surely there must be a way without using VBA to start counting from zero without needing to manually change a reference every time it moves.
I've tried variations of sum(row()-1+row()), mod, gcd. could there be a way to have an absolute reference move with a cell?
I've just figured it out! i can't believe the answer eluded me for so long!
columns($A$1:a1)-1
This will give me a result of zero, and increments when filled across.
0 1 2 3 ...
rows($A$1:a1)-1 will do the same for rows.
I know it references a cell, but this way it doesn't matter which cell this formula is placed into, the result will always be the same. However if you insert of delete cells, just refill the formula through the desired cells.
I think this will be much easier than column()-column($A$1).
Thanks guys for your help.
I am trying to further my knowledge in excel, I have searched around all day for an answer to my current question but I was unable to find anything relating to my needs.
I basically, want to know if it is possible to reference which column a formula should use, by storing it in a cell.
So if I have a formula which is using column - Test!C:C, am I able to store that string in a cell and reference that cell in the formula? I have many formulas which are using the same reference, so if i decide to change what column i want to utilize, it takes some time to remove them all.
I know i can use replace all, but it would be fantastic if there was a method to reference a column via a cell.
Use the Indirect Function:
If the cell in which you put the column Address "Test!C:C" was A1, you would use:
=INDIRECT(A1)
If the sheet never changed and you only wanted to reference the column. So in A1 you only want to put "C":
=INDIRECT("Test!" & A1 & ":" & A1)
Indirect lets you enter a string that is then used as a reference.
There is one major draw back to the INDIRECT() function, it is volatile. This means that it will calculate every time excel calculates, not only when the reference cells change. So depending on the number of formulas, it will slow the calculation times.
Is it possible in Google Spreadsheets to reach the value of the cell just above?
Meaning: In one cell A2 I want to display the value from the cell above, that is A1. Not because it is that coordinate, but because it is the cell above. I do this by simply setting the value equal to the above cell:
If I create a new row in between those two, I get this:
As we know, no change in the values, since the reference is not relative in this way. How can I make it relative to the cell, so I always pick the cell above nomatter what is changed? I want the result to be this:
The term relative is wrong in the case of course, but I hope you get my point. I both want the usual relative behavior (so I can move the cell itself and its reference will fit to the new coloumn and row) as well as the behavior that the reference does not point towards a specific fixed coordinate but rather a specific path from the cell itself.
You can address it using the following function:
=INDIRECT(ADDRESS(ROW()-1;COLUMN()))
COLUMN() returns a numeric reference to the current column
ROW() returns a numeric reference to the current row.
In the example here, subtracting 1 from the row gives you the previous row. This math can be applied to the ROW() and/or the COLUMN(), but in answering your question, this formula will reference the cell above.
Then we have ADDRESS() which accepts a numeric row and column reference and returns a cell reference as a string.
Finally INDIRECT() allows you to pass a cell reference in as a string, and it processes it as a formula.
Google Spreadsheets give you help hints as you type, so you should get a full explanation of each function as you type the formula above in.
For anyone who stumbles across this question, you can also specify the column by doing something like this:
=INDIRECT("A" & ROW()-1)
This comes in handy if you are returning values in Column B but checking against the previous row in Column A.
The shortest, and easier for VisiCal old timer is the old RC syntax with relative values…
=INDIRECT("R[-1]C[0]"; FALSE)
Very visual, simple code template to remember and modify, and very short.
Regards, Antoine
How do I obtain a reference to the current cell?
For example, if I want to display the width of column A, I could use the following:
=CELL("width", A2)
However, I want the formula to be something like this:
=CELL("width", THIS_CELL)
Several years too late:
Just for completeness I want to give yet another answer:
First, go to Excel-Options -> Formulas and enable R1C1 references. Then use
=CELL("width", RC)
RC always refers the current Row, current Column, i.e. "this cell".
Rick Teachey's solution is basically a tweak to make the same possible in A1 reference style (see also GSerg's comment to Joey's answer and note his comment to Patrick McDonald's answer).
Cheers
:-)
Create a named formula called THIS_CELL
In the current worksheet, select cell A1 (this is important!)
Open Name Manager (Ctl+F3)
Click New...
Enter "THIS_CELL" (or just "THIS", which is my preference) into Name:
Enter the following formula into Refers to:
=!A1
NOTE: Be sure cell A1 is selected. This formula is relative to the ActiveCell.
Under Scope: select Workbook.
Click OK and close the Name Manager
Use the formula in the worksheet exactly as you wanted
=CELL("width",THIS_CELL)
EDIT: Better solution than using INDIRECT()
It's worth noting that the solution I've given should be preferred over any solution using the INDIRECT() function for two reasons:
It is nonvolatile, while INDIRECT() is a volatile Excel function, and as a result will dramatically slow down workbook calculation when it is used a lot.
It is much simpler, and does not require converting an address (in the form of ROW() COLUMN()) to a range reference to an address and back to a range reference again.
EDIT: Also see this question for more information on workbook-scoped, sheet dependent named ranges.
EDIT: Also see #imix's answer below for a variation on this idea (using RC style references). In that case, you could use =!RC for the THIS_CELL named range formula, or just use RC directly.
You could use
=CELL("width", INDIRECT(ADDRESS(ROW(), COLUMN())))
=ADDRESS(ROW(),COLUMN(),4) will give us the relative address of the current cell.
=INDIRECT(ADDRESS(ROW(),COLUMN()-1,4)) will give us the contents of the cell left of the current cell
=INDIRECT(ADDRESS(ROW()-1,COLUMN(),4)) will give us the contents of the cell above the current cell (great for calculating running totals)
Using CELL() function returns information about the last cell that was changed. So, if we enter a new row or column the CELL() reference will be affected and will not be the current cell's any longer.
A2 is already a relative reference and will change when you move the cell or copy the formula.
=ADDRESS(ROW(),COLUMN())
=ADDRESS(ROW(),COLUMN(),1)
=ADDRESS(ROW(),COLUMN(),2)
=ADDRESS(ROW(),COLUMN(),3)
=ADDRESS(ROW(),COLUMN(),4)
Without INDIRECT(): =CELL("width", OFFSET($A$1,ROW()-1,COLUMN()-1) )
I found the best way to handle this (for me) is to use the following:
Dim MyString as String
MyString = Application.ThisCell.Address
Range(MyString).Select
Hope this helps.
Inside tables you can use [#] which (unfortunately) Excel automatically expands to Table1[#] but it does work. (I'm using Excel 2010)
For example when having two columns [Change] and [Balance], putting this in the [Balance] column:
=OFFSET([#], -1, 0) + [Change]
Note of course that this depends on the order of the rows (just like most any other solution), so it's a bit fragile.
There is a better way that is safer and will not slow down your application. How Excel is set up, a cell can have either a value or a formula; the formula can not refer to its own cell. You end up with an infinite loop, since the new value would cause another calculation... . Use a helper column to calculate the value based on what you put in the other cell. For Example:
Column A is a True or False, Column B contains a monetary value, Column C contains the folowing formula:
=B1
Now, to calculate that column B will be highlighted yellow in a conditional format only if Column A is True and Column B is greater than Zero...
=AND(A1=True,C1>0)
You can then choose to hide column C
Full credit to the top answer by #rick-teachey, but you can extend that approach to work with Conditional Formatting. So that this answer is complete, I will duplicate Rick's answer in summary form and then extend it:
Select cell A1 in any worksheet.
Create a Named Range called THIS and set the Refers to: to =!A1.
Attempting to use THIS in Conditional Formatting formulas will result in the error:
You may not use references to other workbooks for Conditional Formatting criteria
If you want THIS to work in Conditional Formatting formulas:
Create another Named Range called THIS_CF and set the Refers to: to =THIS.
You can now use THIS_CF to refer to the current cell in Conditional Formatting formulas.
You can also use this approach to create other relative Named Ranges, such as THIS_COLUMN, THIS_ROW, ROW_ABOVE, COLUMN_LEFT, etc.
EDIT: the following is wrong, because Cell("width") returns the width of the last modified cell.
Cell("width") returns the width of the current cell, so you don't need a reference to the current cell. If you need one, though, cell("address") returns the address of the current cell, so if you need a reference to the current cell, use indirect(cell("address")). See the documentation: http://www.techonthenet.com/excel/formulas/cell.php
Reference to a cell that include this formula (self reference):
address(row();column())
E.g. getting the value of the cell above:
indirect(address(row()-1;column()))
Or what the OP asked:
=Cell(width;address(row();column()))