Color Detection in Excel via VBA
Solved
Kilyox
-
Kilyox -
Kilyox -
Hello,
I would like to know how to detect if there is a red cell (for example) in an Excel sheet and, if so, increment a counter with the number of cells found.
I can only detect if the selected cell is red or not, but that’s just a matter of having eyes...
I don’t know VBA very well, but I’m quite good with VB.
Could you please help me?!
Thanks in advance
I would like to know how to detect if there is a red cell (for example) in an Excel sheet and, if so, increment a counter with the number of cells found.
I can only detect if the selected cell is red or not, but that’s just a matter of having eyes...
I don’t know VBA very well, but I’m quite good with VB.
Could you please help me?!
Thanks in advance
Configuration: Windows XP Firefox 3.0.1
4 answers
-
Houhou!!!!1 my first VBA code
Sub RedColor()
Dim i, j, n As Integer
n=0
For i = 1 To 10
For j = 1 To 10
If Cells(i, j).Interior.ColorIndex = 3 Then n = n + 1
Next j
Next i
Cells(1, 1) = n
End Sub
It counts the number of red cells between row 10 and column 10
you can change the search size by increasing i and j
it gives the result in A1 you can change that
if you want to change the color 3 it's red, the rest I don't know -
Hello,
to get the list of colorIndex, press F1 and in the search box type PatternColorIndex, property
You'll get the page with the colors and their numbers.
See you later
--
Experience teaches more surely than advice. (André Gide) -
To search for color...
Sub SearchColor() Dim Color As Integer Dim Cell As Range Dim Counter As Integer Color = 3 Sheets("Sheet1").Select ' adjust to the sheet name For Each Cell In Range("A1:J10") ' adjust the range to the cells to test If Cell.Interior.ColorIndex = Color Then Counter = Counter + 1 Next MsgBox "There are " & Counter & " cells with color No. " & Color End Sub
See you later
--
Experience teaches more surely than advice. (André Gide) -