ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Color of cell. (https://www.excelbanter.com/excel-programming/331198-color-cell.html)

Tom

Color of cell.
 
Hello,

how can I identify which "fill color" is used on cell.

For example:

whatColor = range("A1")
If whatColor = 1 then ....


thanks Tom



Mangesh Yadav[_4_]

Color of cell.
 
If Range("A1").Interior.ColorIndex = 1 then


Mangesh



"Tom" wrote in message
...
Hello,

how can I identify which "fill color" is used on cell.

For example:

whatColor = range("A1")
If whatColor = 1 then ....


thanks Tom





Norman Jones

Color of cell.
 
Hi Tom,

Sub Tester()
Dim rng As Range
Dim iColor As Long

Set rng = Range("A1")

iColor = rng.Interior.ColorIndex

If iColor = 6 Then
'do something
Else
'do something else
End If

End Sub

---
Regards,
Norman



"Tom" wrote in message
...
Hello,

how can I identify which "fill color" is used on cell.

For example:

whatColor = range("A1")
If whatColor = 1 then ....


thanks Tom




Patrick Molloy[_2_]

Color of cell.
 
if you use the .Color property, then you avoid possible issues where
different users have changed their color palette - to a degree.
Also, using SELECT CASE can make your code a little more flexible...

Option Explicit
Enum eColors
Red = 3
Blue = 5
Green = 4
Brown = 9
End Enum
Sub Test()
Select Case Selection.Interior.ColorIndex
Case eColors.Blue
'process blue cell
Case eColors.Brown
'process brown cell
' etc etc
Case Else
' color not recognised
End Select
End Sub
Sub ShowColors()
Dim index As Long
Range("A1:B57").Clear
For index = 0 To 56
Cells(index + 1, 1) = index
Cells(index + 1, 2).Interior.ColorIndex = index
Next
End Sub



"Mangesh Yadav" wrote:

If Range("A1").Interior.ColorIndex = 1 then


Mangesh



"Tom" wrote in message
...
Hello,

how can I identify which "fill color" is used on cell.

For example:

whatColor = range("A1")
If whatColor = 1 then ....


thanks Tom







All times are GMT +1. The time now is 09:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com