I want to create a column to print a different text based on the cell color of another cell. So for example, A1 color is green, and A2 is red. So I want B1 and B2 to be "new" and "old", respectively.
My approach is to first create a function to get the color using the below function:
Function ColorIndex(CellColor As Range)
ColorIndex = CellColor.Interior.ColorIndex
End Function
Using `=ColorIndex(A1)', this works great because for it prints a 4 and for red it prints a 3. I can intern use IF to print "old" and "new".
I run into an issue when I try to auto fill the rest of the column with the same formula. Basically I want to use =ColorIndex() for all 76000 rows in column B. I tried double clicking the drag handle and manually selecting Fill, but nothing happened. Any one know why this is happening and is there a way to get around it?
Related
I need to move a cell value to the right 3 columns and highlight this cell in the process.
I'm able to move a cells contents over 3 columns using the below formula:
With Sheets("Sheet1").Cells(22, lastColAmt).MergeArea: .Cut .Offset(0, 3):
End With
I set lastColAmt is equal to the last used column in this row.
However, i'm unable to figure out how to highlight this cell (either prior to moving and then moving with the cell value and highlight or after move to new cell, three columns away but in the same row).
I've tried just adding ".Interior.Color = 65535" or trying to select this cell using another formula but nothing I try moves both the cell value and the highlight. Does anyone know how I can do this?
thank you!
Did you try Sheets("Sheet1").Cells(22, lastColAmt).Interior.Color = 65535 the line before the With? That worked for me.
I'm working on data-analysis where i would like to be able to automatize color fill when looking through large amount of data where there are abundant amount of ghost logs and taking too much of my time as they are severely irrelevant.
So what i would like to do in Excel, is to be able to color fill a cell when the number changes in a column marking a different set of logs.
For instance if there are six rows of log number 456455, i would like the code to color fill the first cell when the number changes to 456456 so that it helps me identify logs faster when i know where the sets are starting. I'm kind of a newbie when it comes to Excel but this loop would help me a lot!
Thx for your time
This can be done with conditional formatting. Use a rule that compares the current cell with the cell in the row above and format if the two are different. Note that you will need to use relative references without $ signs. In the screenshot below, the conditional format is applied from row 2 to 19 and in row 2 the formula compares A2 with A1, in the next row it compares A3 with A2, and so on. If the two cells are different, the cell will change colour.
If you have some knowledge in VBA, you can implement a macro that looks at the column where you have your log number and if the value changes from one cell to another, then you highlight this cell.
I attached a template of code that works for this task.
Sub highlightChange()
Dim preVal As Integer
preVal = 0
For Each o In Range("A:A")
'Go through column
If o.Value <> preVal Then
o.Interior.Color = vbRed 'Color the selection
End If
preVal = o.Value
Next o
End Sub
There may be other solution without VBA, however, it is quite easy and practical to use a macro.
I want to know how I can use an IF statement (or another function) to determine if all the columns pictured below in a particular row are highlighted:
Screenshot of Table
I'm looking to put the function in Column T and return "Buy" if all columns within the row are highlighted.
Thanks in advance
Now I have tested it but not sure what green you use. Change it if I'm incorrrect.
Paste this in a vba module:
Function color(c As Range)
If c.Interior.color = 5296274 Then color = True
End Function
Then use it like:
=color(A1)
It will return true if A1 is green.
In your case you need to build a and like:
=and(color(A1), color(B1))
And so on...
And you need to save the workbook as macroaktivated workbook xlsm.
Edit added picture and other colorcode. This is the left green color of "standard colors".
I am trying to set up an if statement formula that will read the color of one cell and place a value in another based on that color. I have tried writing several if statements to do this but cant find one to read the color. The sheet is set up to read a date cell. I have conditional formatting set up to color my weekends. I need a value "200" to show on days that are not on weekends and "0" to show on weekends.
If you were able to do the conditional formatting, you should be able to use a similar formula to input the value. I am guessing it reads the date cell, figures if it is the weekend or not and then inputs the value.
Assuming, for example, the non-weekends are Red (vbRed) then create a UDF (VBA, Add Module and paste the following:
Public Function checkColor(cell)
If cell.Interior.Color = vbRed Then
checkColor = 200
Else
checkColor = 0
End If
End Function
To use the function:
For example to check A1 and put 0 or 200 in B1, in B1 type
=checkColor(A1)
Is this possible to sum up all values based on the background color of a cell in excel? I have several cells in red and others in yellow and would like to sum the cell colors separately yet automatically?
Do you want to sum only once, or you will be making changes in the spreadsheet and need the new sums?
Are you willing to use macros? Look at http://www.xldynamic.com/source/xld.ColourCounter.html#summing
Also you can create a function with VBA to get the colors of each cell:
Function GetColor(Mycell As Range)
GetColor = Mycell.Interior.ColorIndex
End Function
https://stackoverflow.com/a/10637049/3491999
Then use SUMIF function