Forum Discussion
Color coding cells with drop down list
You can achieve dynamic color coding based on the value in column L using Conditional Formatting in Excel without needing to create multiple formulas for each row. Instead, you'll use a formula that will apply to the entire range O:BV and automatically adjust for each row based on the corresponding value in column L.
Here’s how to set up conditional formatting for multiple rows, where the formula adjusts based on the value in column L:
Steps for Color Coding Cells Based on Drop-Down List in Column L:
1. Prepare Your Drop-Down List in Column L:
- Ensure that column L contains the drop-down list, which users will select from. The values in column L will control the formatting in columns O:BV.
2. Set Up the Conditional Formatting:
- Select the Range:
- Select the range you want to apply the color coding to. In your case, select the range O:BV. Start from the first row of data (e.g., if your data starts in row 7, select O7:BV100 or however far your data goes).
- Open Conditional Formatting:
- Go to the Home tab on the Excel ribbon.
- Click on Conditional Formatting > New Rule.
- Use a Formula for Conditional Formatting:
- In the New Formatting Rule dialog, select Use a formula to determine which cells to format.
- Enter the Formula:
- Use a formula that refers to the corresponding value in column L. Here’s the formula to use:
=COUNTIF(Blad2!$B:$B, $L7) > 0
- This formula checks if the value in column L (e.g., L7, L8, L9, etc.) exists in the list in Blad2!$B:$B. The dollar sign before L locks the column, but allows the row number to change as the formatting is applied to different rows.
5. Set the Format:
- After entering the formula, click Format to choose the color you want to apply to the range O:BV if the condition is met.
- Choose your preferred fill color and click OK.
6. Apply the Rule:
- Click OK to close the formatting dialog.
- The formatting will now be applied dynamically, based on the corresponding value in column L for each row.
3. Result:
- If the value in column L (e.g., L7) is found in Blad2!$B:$B, the corresponding cells in columns O:BV for that row will be color-coded according to the formatting you set.
- This will automatically apply to all rows in the selected range, meaning you don't need to write individual formulas for each row or column.
Explanation of the Formula:
- COUNTIF(Blad2!$B:$B, $L7) > 0:
- This checks if the value in column L of the current row (e.g., L7) exists in the column B of Blad2. If it exists, the formula returns TRUE, triggering the conditional formatting.
- $L7 locks the column L but allows the row number to change dynamically for each row (e.g., L7, L8, L9, etc.).
- The condition checks if the count of the value in column B of Blad2 is greater than 0, indicating that the value exists.
Alternative Based on Multiple Criteria:
If you have more conditions based on different values in the drop-down list (e.g., color code differently for different values), you can create multiple rules with different formulas for different colors.
For example:
- For one condition, use COUNTIF(Blad2!$B:$B, $L7) > 0 to apply one color.
- For another condition, you might use =COUNTIF(Blad2!$C:$C, $L7) > 0 to apply a different color if the value matches a different list in Blad2.
The text, steps and functions were created with the help of AI.
The example file is from my archives and contains various examples with conditional formatting. Unfortunately I no longer know the source or which website I got it from,
maybe it will help additionally.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.
Thanks for the respons and help!
It works, the only hassle is that the values going into column O corresponds to the ones in column C in Blad2, and for column P it is D in Blad2 and so on.
So I would still need a formula per column?
- NikolinoDESep 13, 2024Gold Contributor
We can try modify the solution to still use Conditional Formatting effectively but keep it compatible with what Excel allows.
Here is a approach:
- Apply Conditional Formatting Column by Column:
- Column O: Check values in Blad2!C.
- Column P: Check values in Blad2!D.
- And so on, adjusting the formula for each column.
- For Column O (comparing with column C in Blad2)
Formula for Conditional Formatting in column O:
=COUNTIF(Blad2!$C:$C, $L7) > 0
This formula checks if the value in $L7 exists in Blad2!C.
- For Column P (comparing with column D in Blad2)
Formula for Conditional Formatting in column P:
=COUNTIF(Blad2!$D:$D, $L7) > 0
This formula checks if the value in $L7 exists in Blad2!D.
- For Column Q (comparing with column E in Blad2)
Formula for Conditional Formatting in column Q:
=COUNTIF(Blad2!$E:$E, $L7) > 0
This checks if the value in $L7 exists in Blad2!E.
- Apply these formulas to each column:
- For column R, compare with Blad2!F.
- For column S, compare with Blad2!G.
- And so on, until you cover all the columns you need.
Steps to Apply Conditional Formatting:
- Select the First Column (e.g., O7):
- Go to Home > Conditional Formatting > New Rule.
- Choose Use a formula to determine which cells to format.
- Enter the Formula: For column O, enter:
=COUNTIF(Blad2!$C:$C, $L7) > 0
- Set the Format: Choose a color to highlight the cells where the formula returns TRUE.
- Repeat for Each Column:
- Apply a similar rule to column P with the formula:
=COUNTIF(Blad2!$D:$D, $L7) > 0
- Continue this process for all the columns that need conditional formatting.
Why This Works:
- COUNTIF is fully supported in Conditional Formatting and checks whether the value in column L (e.g., L7, L8, etc.) exists in the corresponding column in Blad2.
- The formula dynamically adjusts for each row (using $L7, $L8, etc.) but stays fixed to compare with the appropriate column in Blad2.
Limitation:
Unfortunately, Excel's Conditional Formatting does not support complex formulas that rely on INDIRECT, INDEX, or dynamic ranges in the way regular formulas do. Therefore, a manual adjustment per column is necessary for this case.
This approach, while a bit repetitive, should meet your needs and be fully compatible with Conditional Formatting. The text, steps and functions were created with the help of AI.
Hope this will help you.