Jun 15 2017
11:51 AM
- last edited on
Jul 25 2018
09:42 AM
by
TechCommunityAP
Jun 15 2017
11:51 AM
- last edited on
Jul 25 2018
09:42 AM
by
TechCommunityAP
I don't know how to code in VBA but am trying to automate an if/then calculation based on cell color. As shown in the picture, if the colors of the cells in column B are the same as those in Column G across the row, I want to subtract the values in columns F and K in the same row to return the absolute value of the subtraction in column L. If the colors of the cells are different, I want to add the values in columns F and K and return the value in column L.
I will have multiple tables of varying numbers of rows where I need to perform this operation. Any help is greatly appreciated.
Jun 15 2017 02:30 PM
SolutionStep 1 Paste code (found at bottom) into a new module. ALT F11 shortcut should open the code area.
Step 2 In cell O1 paste formula: =InteriorColor(B1) drag formula down
Step 3 In cell P1 paste formula: =InteriorColor(G1) drag formula down
Step 4 In cell L1 paste formula: =IF(O1<>P1,F1+K1,ABS(F1-K1)) drag formula down
Does this work for you Laurie?
Cheers,
Kevin
Function InteriorColor(CellColor As Range)
Application.Volatile
InteriorColor = CellColor.Interior.ColorIndex
End Function
Jun 15 2017 02:31 PM
You'll have to save your file as ".xlsm" (m for macro).
Jun 16 2017 08:54 AM
Kevin, this worked like a charm. You are the hero of the day!! Thanks ever so much!
Aug 20 2018 12:40 AM - edited Aug 20 2018 12:41 AM
I'm having a similar problem, let's say on my spreadsheet in column W on a range of W5:W268 has values showing as different colours based on conditional formatting formulas. Now what I want to do in another column is based on the colour in the range W5:W268 I want a word to appear. So if the colour is green, I want the text in the adjacent column to say Active, if the colour is red, Inactive & if the colour orange, Domant. I can't find anywhere online showing me how to achieve this. Thanks heaps
Aug 20 2018 02:01 AM
Hi David,
If you use conditional formatting you may apply same formulas as for conditional formatting rules to your another column to return the text.
Aug 20 2018 04:10 PM
Hi Sergei,
I sort of figured that but I can seem to find a formula to achieve the outcome. Do you have a example formula that might work?
Thanks, David
Aug 21 2018 09:38 AM
David, it depends on which conditional formatting rules you use. If you provide small sample it'll be easier to answer.
Aug 21 2018 03:44 PM
Hi Sergei,
Thank you for replying. I hope the below makes a little more sense.
Below is the criteria I was given and below I have attached a screen shot of the spreadsheet with the relevant columns that my query relates to.
Note: I'm thinking the answer is utilising a IFS & ISBLANK combined formula, but so far I haven't been able to get this combination to work to encompass all three criteria..if that makes sense. So far I have only been able to get the following IF formula to work but it is not the total solution: =IF(W5=0,("Inactive"),("Active"))
Aug 24 2018 08:08 AM
Hi David,
That could be
=IF(C2>0, "Active",IF(B2>0, "Dormant", "Inactive"))
and attached
Aug 26 2018 05:17 PM
Hi Sergei, worked a treat - thanks so much.
Jan 18 2019 02:30 AM
Hi Kelvin
Please help,i want to colour code the cell with green using if formular for a value ranging 50 to 0.That is checking with a certain cell that contains e.g numder of days
Jan 18 2019 02:30 AM
Hi Kelvin
Please help,i want to colour code the cell with green using if formular for a value ranging 50 to 0.That is checking with a certain cell that contains e.g numder of days
Jan 18 2019 04:53 AM
Hi, I got this solution to work for when I manually apply a color to a cell, but it is not working for cells that are highlighted because of the Conditional Formatting I apply on duplicate rows.
I want to easily filter duplicate rows but filtering on color is not working for more than a couple hundred rows....
Thanks!
May 04 2019 02:01 AM
I have created a spreadsheet that has multiple cells that go red based on conditional formatting. I have another sheet that has hyperlink cells to the other sheets, can I get these hyperlink cells to go red if any of the cells on the hyperlinked sheet is red
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("B4").Interior.Color = Me.Range("A1").DisplayFormat.Interior.Color
End Sub
this works on the same sheet but as soon as you introduce multiple cells it turns black
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("B4").Interior.Color = Me.Range("A1:B1:C1").DisplayFormat.Interior.Color
End Sub
or cells from another sheet it fails error code 1004
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("B4").Interior.Color = Me.Range("Greenbrook!$C$3").DisplayFormat.Interior.Color
End Sub
I tried this across sheet, this is for a single cell, I'm hoping to be able to look at all cells on the said sheet and show red if any cell on the other sheet are red
Aug 07 2019 03:09 PM
Mabye you can help me 🙂
I have a value in cell J18 that i would like to return to cell C23 - IF - cell C19 has the color red
Is that possible? 🙂
Aug 08 2019 02:42 PM
@Kevin Lehrbass @Laurie McDowell
I implemented this for a similar problem and it worked well! However, if I change the color of my cell, the output value will not update unless I go into the formal and hit enter. Is there a way this will refresh automatically? I even tried the refresh function for the entire workbook, but that didn't work either.
Aug 23 2019 08:08 AM
Thanks for your code! I don't know why I am having trouble to make it work. The function seems to always give me value 2 whatever the colour of the cell is. Please find the spreadsheet attached (column L).
Many thanks
Paula
Oct 08 2019 10:24 AM
hi
came across this one while searching on a similar issue.
hope will be helpful ...
https://www.ablebits.com/office-addins-blog/2013/12/12/count-sum-by-color-excel/comment-page-2/
good luck.
Dec 03 2019 05:41 AM
@Kevin LehrbassThanks for the great function and reminding me about custom functions. Huge help!
Jun 15 2017 02:30 PM
SolutionStep 1 Paste code (found at bottom) into a new module. ALT F11 shortcut should open the code area.
Step 2 In cell O1 paste formula: =InteriorColor(B1) drag formula down
Step 3 In cell P1 paste formula: =InteriorColor(G1) drag formula down
Step 4 In cell L1 paste formula: =IF(O1<>P1,F1+K1,ABS(F1-K1)) drag formula down
Does this work for you Laurie?
Cheers,
Kevin
Function InteriorColor(CellColor As Range)
Application.Volatile
InteriorColor = CellColor.Interior.ColorIndex
End Function