ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA for Dates and Row Colors (https://www.excelbanter.com/excel-programming/314323-vba-dates-row-colors.html)

Dave Y[_3_]

VBA for Dates and Row Colors
 
Hello,

I need help writing the VBA code to acomplish the
following: I need to find any date in a spreadsheet that
is <= 90 days old; then I want to change the back color of
the row to yellow for those dates. For example if I had
the following data:
Name Acct# AcctCloseDate
This Guy 123456 01/01/2004
That Guy 654321 10/15/2004
Since the first date is over 10 months old (way past 90
days) I would leave the row as it is. Since the second
date is only 6 days old I would want to change the whole
row or at least the cell contaning that date to yellow.
Any help with a solution will be greatly appreciated.
Thank you.

Dave Y

Ron Rosenfeld

VBA for Dates and Row Colors
 
On Thu, 21 Oct 2004 12:42:06 -0700, "Dave Y"
wrote:

Hello,

I need help writing the VBA code to acomplish the
following: I need to find any date in a spreadsheet that
is <= 90 days old; then I want to change the back color of
the row to yellow for those dates. For example if I had
the following data:
Name Acct# AcctCloseDate
This Guy 123456 01/01/2004
That Guy 654321 10/15/2004
Since the first date is over 10 months old (way past 90
days) I would leave the row as it is. Since the second
date is only 6 days old I would want to change the whole
row or at least the cell contaning that date to yellow.
Any help with a solution will be greatly appreciated.
Thank you.

Dave Y


Well, you do it with conditional formatting which can also be done via the
worksheet.

I recorded a macro to do the conditional formatting to generate some VBA code.
I assumed your data was in A2:G100 but you can change this and highlight more
or fewer columns and format more or fewer rows.

I assumed your AcctCloseDate was in column C.

=================================
Sub CF()

[a2].Activate
With Range("A2:G100")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$C2(TODAY()-90)"
With Range("A2:G100").FormatConditions(1).Font
.Bold = True
.Italic = False
.ColorIndex = 2
End With
.FormatConditions(1).Interior.ColorIndex = 3
End With
End Sub
=======================


--ron

Dave Y

VBA for Dates and Row Colors
 
Hi Ron,

Thanks for your quick reply. I'll try your code or take your suggestion of
using conditional formatting tomorrow when I'm back at work. Thanks again.

Dave Y

"Ron Rosenfeld" wrote:

On Thu, 21 Oct 2004 12:42:06 -0700, "Dave Y"
wrote:

Hello,

I need help writing the VBA code to acomplish the
following: I need to find any date in a spreadsheet that
is <= 90 days old; then I want to change the back color of
the row to yellow for those dates. For example if I had
the following data:
Name Acct# AcctCloseDate
This Guy 123456 01/01/2004
That Guy 654321 10/15/2004
Since the first date is over 10 months old (way past 90
days) I would leave the row as it is. Since the second
date is only 6 days old I would want to change the whole
row or at least the cell contaning that date to yellow.
Any help with a solution will be greatly appreciated.
Thank you.

Dave Y


Well, you do it with conditional formatting which can also be done via the
worksheet.

I recorded a macro to do the conditional formatting to generate some VBA code.
I assumed your data was in A2:G100 but you can change this and highlight more
or fewer columns and format more or fewer rows.

I assumed your AcctCloseDate was in column C.

=================================
Sub CF()

[a2].Activate
With Range("A2:G100")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$C2(TODAY()-90)"
With Range("A2:G100").FormatConditions(1).Font
.Bold = True
.Italic = False
.ColorIndex = 2
End With
.FormatConditions(1).Interior.ColorIndex = 3
End With
End Sub
=======================


--ron


Ron Rosenfeld

VBA for Dates and Row Colors
 
On Thu, 21 Oct 2004 18:09:02 -0700, Dave Y
wrote:

Hi Ron,

Thanks for your quick reply. I'll try your code or take your suggestion of
using conditional formatting tomorrow when I'm back at work. Thanks again.


You're welcome. Let me know if any problems.


--ron


All times are GMT +1. The time now is 01:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com