Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
bfmartiniv
 
Posts: n/a
Default How do I check formatting in an if-then statement

I want to build a spreadsheet that as I highlight a cell with a specific
color, I want the value in the cell replaced with a 1. How can I check that
the highlight color of a cell is a certain color? Can this be done with If
Then Logic?
  #2   Report Post  
JE McGimpsey
 
Posts: n/a
Default

Is the value in the cell to be highlighted a calculated value? In that
case, use, for checking if the cell is blue (colorindex = 5)

=IF(COLORIND()=5,1,<your calculation here)

where COLORIND is a User Defined Function:

Public Function ColorInd(Optional ByRef rng As Excel.Range)
Application.Volatile
If rng Is Nothing Then Set rng = Application.Caller
ColorInd = rng.Interior.ColorIndex
End Function

but since changing the color of a cell doesn't trigger calculation,
you'll have to fire it manually, or via another event.

If the cell to be highlighted contains a value instead, you'll have to
use a macro. Again, the problem is that there are no events that are
fired when you change the color of a cell. You could manually
recalculate, and use this event macro (put it in the worksheet code
module):

Private Sub Worksheet_Calculate()
If Range("A1").Interior.ColorIndex = 5 Then _
Range("B1").Value = 1
End Sub

If you're not familiar with UDFs and macros, see David McRitchie's
"Getting Started with Macros and User Defined Functions":

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




In article ,
"bfmartiniv" wrote:

I want to build a spreadsheet that as I highlight a cell with a specific
color, I want the value in the cell replaced with a 1. How can I check that
the highlight color of a cell is a certain color? Can this be done with If
Then Logic?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I use a check box to accept a calculation Joejoethecrackman Excel Discussion (Misc queries) 5 March 22nd 05 08:47 PM
check box formatting jt Excel Discussion (Misc queries) 1 January 18th 05 06:53 PM
check box formatting jt Excel Discussion (Misc queries) 0 January 18th 05 03:49 PM
Copy conditional formatting across multiple rows? Gil Excel Discussion (Misc queries) 1 January 11th 05 11:27 AM
Conditional formatting not available in Excel BAB Excel Discussion (Misc queries) 2 January 1st 05 03:33 PM


All times are GMT +1. The time now is 05:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"