How to get cell background color

M

moonhkt

Hi All

How to get cell background color by Formula ? just in A2 input formula
to get A1 background color.

Excel 2003

moonhkt
 
J

James Ravenswood

Use the following UDF:


Public Function BColor(r As Range) As Long
BColor = r(1).Interior.ColorIndex
End Function


User Defined Functions (UDFs) are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.

To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To use the UDF from Excel:

=BColor(A1)

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

or

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
for specifics on UDFs
 
M

moonhkt

Use the following UDF:

Public Function BColor(r As Range) As Long
BColor = r(1).Interior.ColorIndex
End Function

User Defined Functions (UDFs) are very easy to install and use:

1. ALT-F11  brings up the VBE window
2. ALT-I
    ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.

To remove the UDF:

   1. bring up the VBE window as above
   2. clear the code out
   3. close the VBE window

To use the UDF from Excel:

=BColor(A1)

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

or

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
for specifics on UDFs

Thank for you suggestion. Someone may not like to Open excel with
VBA. So, I am asking how to using formula to check the backgroup
color.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top