In a range of 10 cells i have 2 cells of red colors.
Like I can identify the blank cells using below
Dim rng As Range
Set rng = Range("A1:A10").SpecialCells(xlCellTypeBlanks)
rng.Select
Is there a way to identify cells of specific format (in this case cells with Red color)
as specialcells does not show any relevant option.
I want to identify these red cells in a range preferably without any loop.
Thanks for looking into it.
altering a color in a cell is non-volatile - that means that cells depending on the color will not be updated if their reference cell changes.
Having said that, and also having recommended against using the color to make a decision (when you should try to use the value) you could try the below:
see Using old XLM GET.CELL (function 63) function to reference color
use that function to create an #NA value in the cell (so =IF(...,NA(),"") maybe?
Use SpecialCells to return the cells with #NA (see here for some tips)
I hope that gets you started, at least with some reading that might point you in the right direction.
But again, you should try to make your decision based on a cells value, not formatting
Related
I need to perform some averageif and sumif functions on a database whose criteria is defined by the colour of the text in each row.
Currently, I am manually assigning to each row a value based on the colour of the text (1 for red and 2 for black) in order to perform calculations. The problem is that my file if huge and it's not possible to keep assigning values manually.
I was wondering if there was some excel function that returns a value based on the colour of the text (or any other solution that saves time).
Thank you
I believe the story is not entirely as you say it is, because to my knowledge, you can't store a colour in a database :-)
So, in my opinion, you have two columns in database, one with some label, the other with some value (1 or 2) and you have decided to merge both informations into one column in Excel, where you want the value 1 to be represented by a red colour and 2 by a black colour. (Most probably you either want to emphasize the presence of those values)
For that reason, you can use conditional formatting, as I'm showing you in the following screenshot (using green instead of black):
You can, obviously, choose to hide the column with the value, that won't make a difference for the conditional formatting:
Obviously, your Sumif and AverageIf functions will be based on the values of the B column.
In case VBA is okay in your use case, you can write a function and place it in Module1. You may need to create the Module1 (Alt+F11, Locate your Project, right click and select Insert --> Module)
Text Color
Function getBackCol(Rng As Range) As Variant
getBackCol = Rng.Interior.ColorIndex
End Function
Background Color
Function getFontCol(Rng As Range) As Variant
getFontCol = Rng.Font.ColorIndex
End Function
You can then use the formula like below
=getBackCol(E5)
or
=getFontCol(E5)
it´s my first post.
I have different tables.
for example: range(F9:M16), range(F24:M31) etc.
in A1 I define the row and in B1 I define the column.
example: G3 = 3, H3 = 4
With this information I will create a red bold border in H12.
because in range(F9:M16) is H12 the row 3 and column 4. and in the other ranges are diferent.
so i need a makro, because I do it every time manually.
thanks for your help.
regards
thomas
If you want to highlight cells according to specific conditions, Conditional Formatting is usually the way to go; you can do a lot of very neat things automatically without resorting to a macro.
In this case:
select the range on which you want to apply your format (F9:M16)
create a new conditional formatting, select "Use a formula to determine which cells to format
as a formula, use: =AND(COLUMN(F9)-COLUMN($F$9)=$G$3;ROW(F9)-ROW($F$9)=$H$3)
define your format (red border or whatever else you fancy)
Repeat for all your tables, adapting the references each time. Now the highlighted cell changes according to what you put in $G$3 and $H$3 without you having to do anything.
What this does is, for each cell, get its relative column/row references by calculating the difference from the row/column of the cell being checked (F9 being relativ,e it will change for each cell) and the row/column of the upper-left cell of the range ($F$9 will NOT change) - resulting in a range starting from 0, but since you use 0 in your table, that's fine. If not, you'll need to adjust by adding a constant. If both (the AND part) these indexes match, you apply the formatting. Note that if you use an OR, the whole row and whole column will be highlighted.
thanks for your answer.
Correct, I had already used the Conditional Formatting, but for this case it isn´t optimal.
Because I have no oppurtunities to change the thickness of the borders. I would like to have a red, thick border.
thanks for your help.
regards
thomas
I have a sheet that looks like this:
The coloured cells need to be a specific colour based on their value. I am currently using conditional formatting to achieve this, but I am only able to get it to apply to a single column instead of the entire range A:G. For example, here’s my formula for column A for values that should be coloured light blue:
=OR($A1="CA515",$A1="CA525")
And applies to:
=$A:$A
Using the above formula, if any of the cells in column A contain the value CA515 or CA525, the cell alone is coloured light blue. Is there any way to use a single conditional formatting formula to make it possible that if any of the cells in the range A:G contain the value CA515 or CA525 that only that cell alone is coloured light blue? Or do I have to apply the formula to every column individually, or possibly even resort to VBA?
Thank you in advance!
You can avoid using VBA here*... Remove the dollar signs in your conditional statement, it should be
=OR(A1="CA515", A1="CA525")
The dollar signs specify whether the reference is relative or absolute. To visualise how this works, try typing these formulas into a cell and dragging the corner of the cell down to autofill:
=A1 'Autofilling this down will give =A2, =A3, ...
=$A1 'Autofilling this down will give =$A1, =$A1, ...
So by removing $, your format condition should be spread across the range. To set the range, change "applies to" to $A:$G.
Note: many conditional formats over a large range like this could severely impact the speed of your document. Consider at least limiting the number of different formats, or the number of rows it's checking.
*Although the above method does avoid VBA, it might be quicker to write your own formatting routine in VBA, since it wouldn't have to get checked so frequently and it would be unaffected by moving around of ranges which messes with conditional formats.
I'm currently working in excel, and I'm trying to figure out a way to find if multiple cells contain the string value of another cell, and if it does highlight the cell where the row and column meet up. I created an example of what I want, only it will be on a much larger scale.
I've tried using: =ISNUMBER(SEARCH(substring,text)) but I'm not quite sure how to use it the way I want to.
Any help will be appreciated!
Your approach is correct, we can use the fact that conditional formatting is applied like dragging a formula, adapting relative references.
Create a conditional formatting formula rule:
=ISNUMBER(SEARCH(B$1,$A2))
Applied to B2:D7
Your formula will work nicely; what you'll want to do is put that formula into all the cells you want to highlight, so you get FALSE and TRUE in every cell.
You'll then use two Conditional Formatting rules. The first will look for Cell Value = TRUE, and will set cell background and font colour to yellow. The second will look for Cell Value = FALSE, and will set cell background to No Colour and Font to White.
This will reproduce the result you're looking for.
Edited to add:
It is possible to do this using just Conditional Formatting too, but it's a little more fiddly. If you want to try it, you can do this:
Highlight your range, and take note of which cell is Active - that's the cell within your highlighted range that is still white. It's also the one whose address is shown in the Name box in the upper left. For the sake of this answer, we'll assume that's B2
Create a new Conditional Formatting rule. Choose "Use a formula to determine which cells to format".
Use the formula =ISNUMBER(SEARCH(B$1,$A2). Set the format to colour just the cell background.
Note where the $ appears in the formula above - you want to leave the row number anchored in the first part, and the column letter anchored in the second part.
This takes advantage of the fact that Conditional Formatting is able to use absolute, relative, and mixed references to find which cells to format. It's also a tidier solution, but it can be harder to maintain if the sheet is ever repurposed or modified.
What I'm doing is a simple map on one tab of an office space that has all the cubicals laid out. On this map, I have conditional formatting checking another table of listen computers for the last time they were updated/maintained. It works as it stands, but we are moving into a new building and the map (which is already done) has WAY more cubes than last time. So I'm trying to figure out a more efficient way to do this task.
Here is the code:
=AND(VLOOKUP("CCA C1",LOCATION,3,FALSE)<>"",VLOOKUP("CCA C1",LOCATION,3,FALSE)<TODAY()-80)
So as it sits, it works fine. But what I'm trying to do is change the "CCA C1" to simply read the contents of the cell it's formatting so I can just format an entire range of cells rather than doing it cell by cell. The "CCA C1" is in the location of the second sheet (it's a named range). So this checks that entire range for "CCA C1" and checks if the date a couple columns over in that row is within 80 days, if it's not it highlights the cell in the map in red reminding us we need to check the computer. But what I would like to do is simply put "CCA C1" in the cell in the map (which is already is labeled), and have this check for the value of the cell it's formatting and look for that value the same way it's looking now. Just without me having to put "CCA C1" in the formula, I'd like to say something like this:
=AND(VLOOKUP(CURRENT CELL VALUE,LOCATION,3,FALSE)<>"",VLOOKUP(CURRENT CELL VALUE,LOCATION,3,FALSE)<TODAY()-80)
Make sense? Anyone know of a way to do this? Otherwise I have to conditionally format each individual cell with the value manually rather than just format all the cells with the same formatting and have the formula check the contents of the cell for what to look for in the location range of the other sheet.
And to clarify, I know that I can put in the actual cell, such as E3, but then I still have to manually change the formula for each cell which defeats the purpose. I want to just say current cell or something like that. I have 3 conditional formats for each cell, I have around 100 cells to be formatted, so rather than having 300 formats I have to put in, I'd love to just do 3. Not sure if this is possible, that's why I'm asking :)
Just replace "CCA C1" with the address of the first cell in the range of cells with the conditional formatting. Assuming your conditional formatting starts in B2:
=AND(VLOOKUP(B2,LOCATION,3,FALSE)<>"",VLOOKUP("CCA C1",LOCATION,3,FALSE)<TODAY()-80)
EDIT: As I commented, I'm not sure I understand the issue, but if I do, you need to enter the range of cells with CF in the applies to range of the CF dialog, rather than copying and using Paste Special:
Note that this works with the merged cells.
You will need to adjust the applies to range as you add more computers, etc., but the same formula will work.