Get Color of cell

MetLife

Active Member
Joined
Jul 2, 2012
Messages
330
Office Version
  1. 365
Hi,

I am using excel 2010, and want to get the color integer value.

I tried using

Dim colornumber As Integer
Dim c1 as Range

Set c1 = Range("A1")
colornumber1 = c1.Interior.ColorIndex

But the problem is that "grey" has a "2" value and so does the white space, so it doesn't capture all the colors.

Does anyone know a way to get the values for colors that aren't on the standard palette?

Thanks
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
No ".interior.color" does not run in debug

Are you sure? I tried
Code:
Sub test()
Dim colornumber As Integer
Dim c1 As Range
Set c1 = Range("A1")
colornumber1 = c1.Interior.Color
MsgBox colornumber1
End Sub
Worked fine.
 
Upvote 0
Yes that does work.

For some reason when I switched from one to the other it gave me a stack overflow error...

Sub colornumber()
Dim MyCell As Range, c1 As Range, c2 As Range
Dim colornumber As Integer, colornumber1 As Integer, colornumber2 As Integer, colornumber3 As Integer
Set MyCell = Range("D4")
Set c1 = Range("E8")
Set c2 = Range("E9")
Set c3 = Range("E10")
colornumber1 = c1.Interior.ColorIndex
colornumber2 = c2.Interior.ColorIndex
colornumber3 = c3.Interior.ColorIndex
c1.Interior.ColorIndex = colornumber


colornumber1 = c1.Interior.Color
colornumber2 = c2.Interior.Color
colornumber3 = c3.Interior.Color
c1.Interior.ColorIndex = colornumber
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top