I regularly encounter an issue on Excel 2010 when I create a new rule using a formula. The issue is reproducible on several of my computers. I select several cells (for instance A4:B143) and then create a new rule using one of the following formulas:
=$A4="issue"
=($A4="issue")
then press Enter. The goal is, of course, to see all the rows of which the first cell's value is "issue". But this does not work and when I go to "manage rules", I see that Excel has the following formula:
=$A1048441="issue"
This is the formula that I want but not with the number that I entered. If I manually replace this new formula that comes out of nowhere (in my eyes) with my old formula, everything works correctly and the formula stays =$A4="issue".
Does anyone know what might cause this issue?
Please try selecting from top left to bottom right rather than vice versa.
Without the anchor ($) for rows (has to be left off for the one formula rule to apply throughout the range) the row references are relative - but relative to the active cell rather than to the top row.
The active cell when selecting a range is the one that starts the range selection. So a range that is selected from B143 to A4 has B143 as the active cell (not A4). Relative to that Row4 is 139 rows earlier. For CF, 139 rows earlier than A4 is Row1048441 in Excel 2010 (the rows 'wrap' - the last row, Row1048576, is in effect immediately before Row1, so Row1048441 + 136 gets back to Row1 and plus another 3 from there to get to Row4. 136+3 is the 139 difference).
I was able to do apply it in the following manner:
When I entered the formula, I did not put an = sign before. I just put $a6=issue
Rules:
Data:
Related
Every time I make a new conditional formatting rule it changes and breaks. This happens before I click apply, but after I have created the rule. If I apply the rule it, naturally, applies completely incorrectly, but I don't have any idea what the formula is checking. If I then edit the text of the formula after applying it, it will then work and stay the way I have written it.
It seems to be just adding a long string of numbers at the end of my formula location.
In the images below I am adding a new formula:
=$J1="N"
but after hitting ok it changes to this:
=$J1048564="N"
Not sure what I am doing wrong here, so any help would be greatly appreciated!
The row number does not have a $ sign, so it is relative. It is relative to the cell that was the active cell when the format was defined.
If you apply a format to A1:A1000, but the currently active cell is in row 500, then a relative reference to $A1 in the formula will be interpreted as "The cell 499 rows above the current cell". When that format is applied, then Excel will try to find that position for each row. In row 1, it cannot go 499 cells above, so it starts over at the last cell of the sheet and goes 499 up from there.
Of course you don't want all that.
So, when you define a conditional format that applies to many rows, make sure that the currently active cell is at the top left of the selected range, so any relative cell references will be applied relative to that cell position.
You may want to remove your CF completely and start over.
I would like to highlight a cell which is the closest the a specific value but still lower (below) or equal according to a formula.
For instance, if I have 14 in B4, I would like the cell 13 (or 14) highlighted but not 15 in the range.
The value I need to look for would be in B4 and the range that I must apply the highlight formula to would be L1:L371.
So far, the best result I was able to achieve was with (from what I was able to find using Google or Stackoverflow already existing content):
=SMALL($L1:$L317,COUNTIF($L1:$L371,"<="&$B$4))
Although, not only it selects the value I am looking for, it also selects all the values below.
May someone provide me some help so I can achieve the expected result please?
Thank you for your time and help, it is greatly appreciated.
Based on your description, it seems like you need to find the maximum value of a range (L1:L137) that is less than or equal to an input variable (B4) and highlight that value in the search range. Depending on what version of Excel you have, here's what you need to do:
For Excel 2019 or Excel 365
You can use the MAXIFS function. You would actually put that function in a conditional formatting rule, but more on that in just a second. As a test, put the following code in cell B5:
=MAXIFS($L$1:$L$137,$L$1:$L$137,"<="&$B$4)
The first argument is your "MAX_RANGE", or the range that contains the values you want to find the max of. It is also our "CRITERIA_RANGE", the second argument. The third argument is the criteria itself, which is that the search range must be less than or equal to the value in cell B4. Essentially, we are going through the list and creating a subset of numbers that are less than or equal to our search value, and discarding the rest. I assume you are aware of relative vs. absolute referencing, since you used the "$" anchor in your referenced code. If not, here's a description of the difference.
Now, the result of that formula should be the highest number in the list less than or equal to the search value, but that doesn't highlight it for us in our list. To do this we need conditional formatting. To do this, highlight your data range (L1:L137) and go to the conditional formatting drop down on the home tab of the menu ribbon. Choose "New Rule". On the dialog that pops up, choose, "Use a formula to determine which cells to format". In the formula input box, enter:
=L1=MAXIFS($L$1:$L$137,$L$1:$L$137,"<="&$B$4)
This will compare whether the value in the cell being evaluated (L1, for instance) is equal to the result of that formula we talked about above. Since L1 is only relatively referenced, this formula will work for every cell in the data range.
Now, before you hit "OK" on the dialog, select the Format button. This will allow you to adjust your highlighting and formatting as you desire. Click "OK" on the formatting dialog, then "OK" on the Conditional Formatting Rule dialog. This should now highlight any data cell that is equal specifically to the result of our formula, and not everything that's less than our value.
For Earlier Versions of Excel
The concept is the same in earlier versions of Excel, but unfortunately, the MAXIFS function is not present in these versions. Instead, we must use an array formula. Array formulas are a whole other can of worms, but ExcelJet is an excellent resource. In fact, they talk about this very issue, here.
Unfortunately, we can't put the array formula in the conditional formatting formula like we did above, so we'll need to put this formula on a cell in the worksheet, then the conditional formula should reference that new cell. So in cell B5, if you put:
=MAX(IF(L1:L137=B4,L1:L137)
And then, instead of pressing Enter, you must press Ctl + Shift + Enter
This keyboard combination will tell Excel that you are trying to enter an array formula. If you don't press these keys, then the formula will error. Once you have entered the array formula, if you put your cursor in cell B5, you will see the formula bar at the top has added curly braces ({ , }) around the formula to look like
{=MAX(IF(L1:L137=B4,L1:L137)}
This leads to the same result as above, but is just achieved slightly differently. Now, following the same process described above for conditional formatting, you will simply set the formula to:
=L1=$B$5
And that should be it! Hope this helps!
I am trying to compare one row with another: IF the cells in Row 1 is equal to Row 2, THEN I must have highlighting. I've tried 100 methods for over an hour now. The problem is that Excel keeps the formula the same across the row!! the formula needs to change, meaning: I am NOT trying to highlight the whole row based on just the first cell, the cell needs to dynamically change. First cell to first cell, 2nd to 2nd, etc.
The circled words need to be highlighted.
Sorry to ensure everyone is clear on the requirement, here is my requirement:
The solution, as a brilliant guy below mentioned, was a stupid $ sign.
If you want the circled words to be highlighted, the "Applies To" field should be "=$A$10,$E$10" - to see what rules are being applied in those cells, they need to be part of the current selection or you need to change the selection in "Show Formatting Rules For" to "This Worksheet."
If you want the comparison to not be absolute, remove the dollar signs.
Also consider adding TRIM() around A9 and A10 in the formula if you don't want stray spaces to lead to a detection of a difference.
change the Formula to = A10 = A9 (or just remove the $'s in yours) and Applies To =$A$10:$E$10
I want to change a variable in an excel formula horizontally and maintain one variable constant.
O3/$C18, P3/$C18, Q3/$C18
I can keep the the bottom variable constant by using the $ symbol but when I want to extend the formula to additional cells, the top variable does not change horizontally, rather vertically.
Thank you for your help. Cheers
The dollar signs in excel "fix" the item to their right
$C18
means C will always be fixed, and 18 can change
C$18 means C can change, but 18 is always fixed.
$C$18 means C is fixed and 18 is fixed (ie always use C18 no matter what direction you drag the cell)
I dont fully understand what you want to do but hopefully the above will help
based on the comments below i think i understand what you mean
try a formula like this
=INDIRECT(ADDRESS(1,ROW()))/$C$18
here address takes the row and column, so row = 1 and column = which ever row you are on (so row1 = A, row2=B etc)
then indirect lets you use that as a reference point
Hope that works
If I understand you correctly, you want to copy your formula vertically, but have the columns update as if you were copying horizontally. For example, you want to copy =O3 to the cell below it as =P3.
For the top, consider the Offset() and Row() functions. Let's say that Cells A1,B1,C1 are 1,2, and 3. Try =OFFSET($A$1,0,ROW()-1). If you copy that formula vertically, the result will be 1, then 2, then 3.
So in your case, try =OFFSET($O$3,0,ROW()-1). It probably needs a little adjustment.
Here's another way to do this:
Start with the formula in this form:
=O$3/$P$18
Copy and paste it across so that you get:
=O$3/$P$18 =P$3/$P$18 =Q$3/$P$18
Copy the two formulas you pasted and select the cell below the first formula.
Then do a Paste Special / Transpose, which can be accessed by right-clicking the selected cell (that is, the one below the first formula that you entered) and then choosing the button that shows a little two-cell range flat and then upright.
Finish up by deleting the formulas in the cells you just copied from.
How to get the value of a merged cell of an excel having range address like "$B$4:$B$11" in vba
Even if it is really discouraged to use merge cells in Excel (use Center Across Selection for instance if needed), the cell that "contains" the value is the one on the top left (at least, that's a way to express it).
Hence, you can get the value of merged cells in range B4:B11 in several ways:
Range("B4").Value
Range("B4:B11").Cells(1).Value
Range("B4:B11").Cells(1,1).Value
You can also note that all the other cells have no value in them. While debugging, you can see that the value is empty.
Also note that Range("B4:B11").Value won't work (raises an execution error number 13 if you try to Debug.Print it) because it returns an array.
Josh Brown gave (in a comment) what I think is the best answer:
When I don't know the bounds of the merged area, I get the value with
Range("B6").MergeArea.Cells(1,1).Value
This is helpful in VBA when, for example, you are looping through files that might have merged cells of unknown ranges, so you can be much more general with this method. Thanks Josh!
This can be done in 2 steps:
First name the range of the merged cells; highlight the merged cell then go on the Ribbon Bar: Formulas Tab --> Define Name;
Make sure there are no spaces in the name. Example: defined_Name. Go to the desired cell you wish to see the output/result. In that cell, type: =defined_Name.
Press enter because your done.
(Excel 2016)
I am hoping this will help somebody.
I have found that if you press delete on a merged cell,
the target.cells.count = the number of merged cells.
Whereas if you change the value on the same cell, the target.cells.count = 1
This caused me issues as I was skipping multi selections in my worksheet_change code by testing the number of cells selected.