Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Format cells based on two conditions

Hello,

In Column A are Numbers.

In Column C are Dates.

I'd like to format cells in Column A and Column C based on these conditions:
If the Number in Column A is greater than 90, and if the Date in Column C is
older than 30 days old, fill both cells color red. I prefer to do this in VBA.

Just to clarify, here's an example:

If the cell value in A1 is 91, and the date in C1 is 1/1/2009, I'd like to
have both cells A1 and C1 filled with the color red.

Thanks in advance for your help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Format cells based on two conditions

Right click sheet tabview codeinsert this. Now, when you change col A the
macro will fire
Could also be designed to fire on change of col C, if desired.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 2 Or Target.Column < 1 Then Exit Sub
With Target
.Interior.ColorIndex = 0
.Offset(, 2).Interior.ColorIndex = 0
If .Value 90 And Date - .Offset(, 2) 30 Then
.Interior.ColorIndex = 6
.Offset(, 2).Interior.ColorIndex = 6
End If
End With
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Shariq" wrote in message
...
Hello,

In Column A are Numbers.

In Column C are Dates.

I'd like to format cells in Column A and Column C based on these
conditions:
If the Number in Column A is greater than 90, and if the Date in Column C
is
older than 30 days old, fill both cells color red. I prefer to do this in
VBA.

Just to clarify, here's an example:

If the cell value in A1 is 91, and the date in C1 is 1/1/2009, I'd like to
have both cells A1 and C1 filled with the color red.

Thanks in advance for your help.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Format cells based on two conditions

This is helpful, thank you. Is it possible to run this code on all of Col A,
instead of just when Col A is changed? Maybe some kind of loop would work?

"Don Guillett" wrote:

Right click sheet tabview codeinsert this. Now, when you change col A the
macro will fire
Could also be designed to fire on change of col C, if desired.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 2 Or Target.Column < 1 Then Exit Sub
With Target
.Interior.ColorIndex = 0
.Offset(, 2).Interior.ColorIndex = 0
If .Value 90 And Date - .Offset(, 2) 30 Then
.Interior.ColorIndex = 6
.Offset(, 2).Interior.ColorIndex = 6
End If
End With
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Shariq" wrote in message
...
Hello,

In Column A are Numbers.

In Column C are Dates.

I'd like to format cells in Column A and Column C based on these
conditions:
If the Number in Column A is greater than 90, and if the Date in Column C
is
older than 30 days old, fill both cells color red. I prefer to do this in
VBA.

Just to clarify, here's an example:

If the cell value in A1 is 91, and the date in C1 is 1/1/2009, I'd like to
have both cells A1 and C1 filled with the color red.

Thanks in advance for your help.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Format cells based on two conditions

sub runcola()
for i=1 to cells(rows.count,1).end(xlup).row

With cells(i,1)
.Interior.ColorIndex = 0
.Offset(, 2).Interior.ColorIndex = 0
If .Value 90 And Date - .Offset(, 2) 30 Then
.Interior.ColorIndex = 6
.Offset(, 2).Interior.ColorIndex = 6
End If
End With
next i
end sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Shariq" wrote in message
...
This is helpful, thank you. Is it possible to run this code on all of Col
A,
instead of just when Col A is changed? Maybe some kind of loop would work?

"Don Guillett" wrote:

Right click sheet tabview codeinsert this. Now, when you change col A
the
macro will fire
Could also be designed to fire on change of col C, if desired.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 2 Or Target.Column < 1 Then Exit Sub
With Target
.Interior.ColorIndex = 0
.Offset(, 2).Interior.ColorIndex = 0
If .Value 90 And Date - .Offset(, 2) 30 Then
.Interior.ColorIndex = 6
.Offset(, 2).Interior.ColorIndex = 6
End If
End With
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Shariq" wrote in message
...
Hello,

In Column A are Numbers.

In Column C are Dates.

I'd like to format cells in Column A and Column C based on these
conditions:
If the Number in Column A is greater than 90, and if the Date in Column
C
is
older than 30 days old, fill both cells color red. I prefer to do this
in
VBA.

Just to clarify, here's an example:

If the cell value in A1 is 91, and the date in C1 is 1/1/2009, I'd like
to
have both cells A1 and C1 filled with the color red.

Thanks in advance for your help.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Format cells based on two conditions

Everything appears to be working. Thank you very much!

"Don Guillett" wrote:

sub runcola()
for i=1 to cells(rows.count,1).end(xlup).row

With cells(i,1)
.Interior.ColorIndex = 0
.Offset(, 2).Interior.ColorIndex = 0
If .Value 90 And Date - .Offset(, 2) 30 Then
.Interior.ColorIndex = 6
.Offset(, 2).Interior.ColorIndex = 6
End If
End With
next i
end sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Shariq" wrote in message
...
This is helpful, thank you. Is it possible to run this code on all of Col
A,
instead of just when Col A is changed? Maybe some kind of loop would work?

"Don Guillett" wrote:

Right click sheet tabview codeinsert this. Now, when you change col A
the
macro will fire
Could also be designed to fire on change of col C, if desired.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 2 Or Target.Column < 1 Then Exit Sub
With Target
.Interior.ColorIndex = 0
.Offset(, 2).Interior.ColorIndex = 0
If .Value 90 And Date - .Offset(, 2) 30 Then
.Interior.ColorIndex = 6
.Offset(, 2).Interior.ColorIndex = 6
End If
End With
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Shariq" wrote in message
...
Hello,

In Column A are Numbers.

In Column C are Dates.

I'd like to format cells in Column A and Column C based on these
conditions:
If the Number in Column A is greater than 90, and if the Date in Column
C
is
older than 30 days old, fill both cells color red. I prefer to do this
in
VBA.

Just to clarify, here's an example:

If the cell value in A1 is 91, and the date in C1 is 1/1/2009, I'd like
to
have both cells A1 and C1 filled with the color red.

Thanks in advance for your help.






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 to sum cells based on conditions tjd59 Excel Worksheet Functions 2 April 23rd 09 03:56 PM
How do I format a cell based on conditions in five different cells dallasfinance Excel Discussion (Misc queries) 1 February 19th 09 09:43 PM
shade cells based on conditions - i have more than 3 conditions Mo2 Excel Worksheet Functions 3 March 30th 07 07:19 AM
Conditional Formatting 4+ conditions, format rows based on cell nockam[_4_] Excel Programming 10 July 12th 06 11:12 PM
Averaging Cells Based On Conditions in Neighboring Cells foofoo Excel Discussion (Misc queries) 3 June 21st 06 03:10 AM


All times are GMT +1. The time now is 05:44 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"