LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default How do i format cell to change colour as the number increases

Try this one...if should do want you want as below

Private Sub CommandButton3_Click()
Dim j As Integer
On Error GoTo Errhandler
For j = 1 To 4 ' set number columns wide you want If you have 4 names
then this is 4

If Cells(2, j).Value < "" Then ' check the row 2 for the
date is not empty
If Len(Cells(2, j).Value) = 8 Then
Cells(3, j).Value = Date ' enters today date in
row 3 for each name

If DateDiff("m", Cells(2, j).Value, Date) <= 6
Then ' checks date is less/equal than/to 6 months
Cells(4, j).Value = "VALID"
Cells(4, j).Interior.Color = vbBlue
Else
Cells(4, j).Value = "Expired"
Cells(4, j).Interior.Color = vbRed
End If
Else
MsgBox " Invalid Date Entry in Vell " &
Replace(Cells(2, j).Address, "$", "")
Cells(4, j).Value = ""
Cells(2, j).Value = ""
Cells(4, j).Interior.ColorIndex = xlNone
End If

Else
Cells(4, j).Value = ""
Cells(4, j).Interior.ColorIndex = xlNone
End If
Next j
Exit Sub
Errhandler:
If Err.Number = 13 Then

MsgBox " Invalid Date Entry in Vell " & Replace(Cells(2, j).Address,
"$", "") ' for if he date is not entered right
Cells(2, j).ClearContents
Err.Clear
Else
End If

End Sub
Lanre Bex Ayoade wrote:
Please see below, this is all i want to do, I will only need to input the
current date (A3) and get either 'valid' with blue colour or Expired with red
colour in A4
A1 Ade Shola Bex Niyi
A2 3/4/06 4/1/06 23/2/06 26/2/06
A3 31/8/06 31/8/06 31/8/06 31/8/06
A4 'valid' 'Expired' 'Expired' 'Expired'



"stevebriz" wrote:


Lanre,
Is there more cells than jsut A2 -A4 you want this to "effect" to occur
on?
If so please tell me how which cells you want this to affect.
This is code that you put in a through VBA( Press ALT F11) and this
brings up the Vbeditor
You then double click where it says sheet1 in the project explorer and
paste this code in
(This is assuming you are working on sheet 1)
Whenever you change A2 the color will change
The ":valid" will checked when any cell on the sheet is changed....or
do you want this to be automatic when you open the sheet?






 
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
Conditionl format a cell to change text colour PAULANDBEX24 Excel Discussion (Misc queries) 7 October 7th 08 09:05 AM
Change the colour of numbers in a cell if the number is negative bryno Excel Worksheet Functions 3 March 5th 08 09:27 PM
change a cell background colour to my own RGB colour requirements Stephen Doughty Excel Discussion (Misc queries) 4 June 16th 06 01:08 PM
Change cell Colour when a number of days have been passed SR7133 Excel Discussion (Misc queries) 4 March 1st 06 10:49 PM
Change colour of Text if number in cell exceed limit Lewis Koh Excel Worksheet Functions 2 August 2nd 05 02:16 AM


All times are GMT +1. The time now is 09:24 AM.

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"