Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA-Changing cell color with if then function

I am using office 2000 and tring to write a function in which th
argument is multiplied by 12. If the result is less than 36 I woul
like the answer to be highlited in a red cell. If it is greater that o
equal to 36 it will remain a white cell. What I have written gives m
the numerical answer but does not change the color of the box. This i
what I have. Thank you for your help
Mike

Public Function mult(a As Single) As Single
mult = a * 12
If 36 mult Then

ActiveCell.Interior.ColorIndex = 3
Else
ActiveCell.Interior.ColorIndex = 2
End If

End Functio

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 188
Default Excel VBA-Changing cell color with if then function

"red5 " wrote in message
...

I am using office 2000 and tring to write a function in which the
argument is multiplied by 12. If the result is less than 36 I would
like the answer to be highlited in a red cell. If it is greater that
or equal to 36 it will remain a white cell. What I have written
gives me the numerical answer but does not change the color
of the box.
This is what I have. Thank you for your help
Mike

Public Function mult(a As Single) As Single
mult = a * 12
If 36 mult Then

ActiveCell.Interior.ColorIndex = 3
Else
ActiveCell.Interior.ColorIndex = 2
End If

End Function


I don't think you can be sure that the activecell is the cell with the
formula in.

The function would be called everytime that cell has to re-calculate,
but the activecell would not move around during that process I think.

Why not just use conditional formatting on the cell outide of VBA?

Alan.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Excel VBA-Changing cell color with if then function

Hi red5

Have a look at Conditional Formatting within Excel help. Extract below.

1. Do one of the following:
To use values in the selected cells as the formatting criteria, click Cell
Value Is, select the comparison phrase, and then type a constant value or a
formula. If you enter a formula, start it with an equal sign (=).

To use a formula as the formatting criteria (to evaluate data or a
condition other than the values in selected cells), click Formula Is and
then enter the formula that evaluates to a logical value of TRUE or FALSE.

2. Click Format.
3. Select the formatting you want to apply when the cell value meets the
condition or the formula returns the value TRUE.
4. To add another condition, click Add, and then repeat steps 1 through
3. You can specify up to three conditions. If none of the specified
conditions are true, the cells keep their existing formats.

--
XL2002
Regards

William



"red5 " wrote in message
...
| I am using office 2000 and tring to write a function in which the
| argument is multiplied by 12. If the result is less than 36 I would
| like the answer to be highlited in a red cell. If it is greater that or
| equal to 36 it will remain a white cell. What I have written gives me
| the numerical answer but does not change the color of the box. This is
| what I have. Thank you for your help
| Mike
|
| Public Function mult(a As Single) As Single
| mult = a * 12
| If 36 mult Then
|
| ActiveCell.Interior.ColorIndex = 3
| Else
| ActiveCell.Interior.ColorIndex = 2
| End If
|
| End Function
|
|
| ---
| Message posted from
http://www.ExcelForum.com/
|



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
Changing the color of a cell based on the color of another cell. LATC Excel Discussion (Misc queries) 7 December 4th 09 09:49 PM
Changing Cell Color Spz Excel Discussion (Misc queries) 2 December 5th 07 08:46 AM
Color changing of fonts by using the IF function sadat Excel Worksheet Functions 1 May 31st 07 08:55 AM
Changing cell color David Excel Programming 2 December 9th 03 01:17 AM
Changing a cell color.... Shaul Excel Programming 2 October 27th 03 09:14 PM


All times are GMT +1. The time now is 04:55 PM.

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

About Us

"It's about Microsoft Excel"