I am trying to write a rule in vba to trigger a Conditional Format, but I have my doubts if I am writing it correctly.
The condition for the format would be, if the cell value of a range is equal to the cell value of the same range on a different sheet:
=M7=Original!M7
This is to applied for all cells in a range (M7:BZ5000) [5000 is a large outer bound number to help conserve memory].
The issue that has me perplexed is how do I tell vba that M7=Original!M7, M8=Original!M8, Z143=Original!Z143, etc.
I feel this is a pretty basic concept but I searched these forums and could not find an answer that I think applies to my issue.
Also, Since I Would want this conditional format to trigger at the press of a button, how would I tell it to deactivate, WITHOUT removing the rest of my conditional formats (I have normal conditional formats applied to the range and want them to remain whenever the button isn't pressed.
Sheets("Main").Select
Range("M7:BZ5000").Select
For Each Cell In Selection
If Cell.Interior.Color = Excel.XlRgbColor.rgbBlack Then
Cell.Clear
End If
Next
You are using the conditional formatting choice of "Use formula to determine which cells to format"
The formula you will need is going to be like this (note the use of $ signs to control how the formula changes. The $ stops the value after it from changing)
=AND($M7=Original!$M7,$G$4="Y")
Note $G$4 is a cell you can use to turn on and off the cond. formatting. When it is "Y" the formatting will work, otehrwise any formatting you have applied will JUST be shown.
If you don't want you formatting to show when conditional formatting is on, then your conditional formatting MUST have formats the remove yours and sets them to the "default" settings.
Related
I'm trying to set conditional formatting in a specific group of cells J9:N12 with a locked cell I9 (110). In Cells J9:N12 I need the conditional formatting to set 1,2,7,8,13,14 as Black Fill w/ White Text, 3,4,9,10,15,16 as Red Fill w/ Black Text, 5,6,11,12,17,18 as Blue Fill w/ White Text. Then if I Change (I9) to 277 the Fills would change to reflect Brown/Orange/Yellow in place of the Black/Red/Blue.
Yes, I can Conditional Format the cells I need based on the information set in cell (I9) 110 or 277.
The series of numbers I need to format is greater than 120. I cannot set Conditional Formatting for each specific number needed. Minimallistically I need to be able to set Conditional Formatting to around 150-160 numbers.
I don't know if I need to utilize VBA or if Conditional Formatting is the way to go.
You could use conditional formatting for this. I'd be tempted to put the number series in an array and test for a find in the array using MATCH. This way, you'd only need as many conditional formatting rules as there are number series.
I'm not certain, but I believe you can't write an array directly into a conditional format rule, but you could refer to it from something like a range name. In any event, a range name would be easier to manage if you needed to change any of the number series.
For example, in the black/brown case, you could create a range name (Formulas->Define Name), called black-brown, and in the Refers To window, have the formula:
={1,2,7,8,13,14}
Then your conditional formatting rule would be something like:
=AND($I$9=110,NOT(ISNA(MATCH(B2,black_brown,0))))
Note my cell to be tested is in B2 - change that to whatever you need.
You'd just add rules for each of your number series cases, as shown below:
I tried selecting the entire range (e.g. A2 to Z400), then put in the condition for instance: =B2<A2 to hope that a "ranged" conditional format would apply, but it doesn't seem to be the case.
I can probably come up with a VBA solution, but I was hoping to have an built-in Excel method if possible
Utilize conditional formating is indeed possible.
Select the desired range.
Select Conditional Formatting.
New Rule..
Use a forumla to determine which cells to format.
For the formula, enter
=IF(B1<A1;1;0)
Also, choose how you which to format.
This checks wheter B1 is smaller than A1. If true, it would return 1 which is boolean for true. This logical test should solve your issue. See screenshot below for the rule applied to range A1:B5.
Rule applied to range A1:B5 EXAMPLE
I have been trying to change the color of certain cells on my WS that fall outside of an acceptable range. The statement I've been trying to use is,
IF(OR('cell'>1.3,'cell'<2.5),'turn red','do nothing')
In english, "If a cell is less than 1.3 or greater than 2.5 turn red, else do nothing." I cannot find a resource that guides me to how I can get the cells to change colors. I also have been unsuccessful in creating a statement in the Conditional Formatting tab that satisfies my goal. I feel this should be simple, but for some reason cannot figure it out. Does anyone know if this is possible, and if so how to do it?
EDIT: Also, I have different ranges based on another cell on the spreadsheet. I need this also taken into consideration
Select the columns that you want to format
Click Conditional format --> new rule
Select "Use a formula to determine which cells to format"
In the formula bar enter the formula =AND(A1>1.3,A1<2.5)
Choose the fill color as red and press OK
am confused with your formula and your english version. If its the other way, then use the formula =OR(A1<1.3,A1>2.5)
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.
I believe this is probably an easy macro; it does not appear to be possible with conditional formatting and I have limited experience with macros.
I have many rows in an Excel workbook. What I'd like to is say:
If I place a < sign in the currently selected cell, then cell immediately to the right should format as bold, otherwise, it should not be emboldened.
I have fooled around with different "IF" statements, but I think I'm way off base.
How in the world do I do this?
EDIT
Here is perhaps a better way to show this, because for some reason I still cannot get it to work; I've included a screenshot.
(Actually, I realized that I asked the question backwards...it should be that if there if there is a cell with a "<" sign then the cell immediately to the right should not be bold).
Anyways, let's focus on row 12 for the sake of an example. It would be nice to have a formula to apply to the entire row that says "look at cell C12. If there is nothing in it, then D12 is emboldened. Look at cell E12, if there is nothing in it then F12 should be emboldened, etc. Look at cell Q12. If it has a "<" sign, then R12 should not be emboldened". The only exception to this would be cells that contain a "--"...those do not need to be emboldened.
With CF, select the range of cells to apply the formatting to - say Columns B:M (not A because that has no "immediately to the left") - HOME > Styles - Conditional Formatting, New Rule..., Use a formula to determine which cells to format and Format values where this formula is true::
=A1="<"
Format..., select Bold, OK, OK.
Edit By "those do not need to be emboldened" I take it you don't mind if they are. That might allow you to embolden the entire sheet (or rather ColumnsC:X) and apply a single conditional format. However that would result in the < themselves being emboldened and I take it you would prefer not. So if formatting is to be applied according to two separate conditions two separate rules are required. Select Columns D:X and for *bold**:
=C1=""
For Regular, with the same range selection:
=C1="<"
You're right, it is an easy macro. And #Scott Craner is correct as well; conditional formatting will work. However, there are times when you already have a lot of conditional formatting and adding another rule becomes a bit tricky, so here is the macro. Put it in the ThisWorkbook section.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Value = "<" Then
Sh.Cells(Target.Row, Target.Column + 1).Font.Bold = True
End If
End Sub
As you can see, you can make your own little formatting rules by checking the value of the cell that changed.
To learn more, search up "Learn Excel". Plenty of resources.