If Statement

  • Thread starter Thread starter DME
  • Start date Start date
D

DME

Is there a way to produce an IF statemnt that relates to the Fill Color of a
Cel. For instance IF(the Fill Color of A1 = Red, then I want B2 * C2, IF
not then b2 *d2) .

I thought I saw something in this newsgroup beefore on this but I was unable
to find it.

Thanks in advance for help.
 
I opened a new workbook and went into VBA editor and entered the following
into this workbooks Microsoft Workbook Objects section:


Function CellColorIndex(InRange As Range, Optional _
OfText As Boolean = False) As Integer
'
' This function returns the ColorIndex value of a the Interior
' (background) of a cell, or, if OfText is true, of the Font in the cell.
'
Application.Volatile True
If OfText = True Then
CellColorIndex = InRange(1,1).Font.ColorIndex
Else
CellColorIndex = InRange(1,1).Interior.ColorIndex
End If

End Function

Then typed changed the font color of cell C8 to Red. And insert the
following formula in to D8:



=CELLCOLORINDEX(A1,FALSE)

The result is #Name?.



Any suggestions as to what I may have done wrong? Thanks.
 
DME

Move the Function out of ThisWorkbook into a General Module.

Insert>Module to create one.

Cut and paste the Function to that module.


Gord Dibben Excel MVP
 
Thank You! It Works!!


Gord Dibben said:
DME

Move the Function out of ThisWorkbook into a General Module.

Insert>Module to create one.

Cut and paste the Function to that module.


Gord Dibben Excel MVP
 

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

Similar Threads

if statements 1
count missing field 2
if statement 2
Need help for a formula 5
Conditional Formatting with if statement 1
If Statement 3
Populate cell is another cell is populated 2
Is it possible to do this? 1

Back
Top