Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
billo
 
Posts: n/a
Default How do I set a date range for conditional formatting in a macro?

I am looking to write a macro that will check for a date range in a group of
cells (for example: today through one year ago today) in a worksheet. Then
I would like to highlight the cells that fall within this date range in bold
red. So far, all I get are syntax errors when trying to write this macro.
Any ideas?
  #2   Report Post  
Jason Morin
 
Posts: n/a
Default

Assuming dates are in col. A, select col. A., go to
Format Conditional Formatting, Formula Is and put:

=AND($A1=TODAY()-365,$A1<TODAY())

Press the Format radio button and format as desired.

HTH
Jason
Atlanta, GA

-----Original Message-----
I am looking to write a macro that will check for a date

range in a group of
cells (for example: today through one year ago today)

in a worksheet. Then
I would like to highlight the cells that fall within

this date range in bold
red. So far, all I get are syntax errors when trying to

write this macro.
Any ideas?
.

  #3   Report Post  
 
Posts: n/a
Default

hi,
a much easier way would be to use conditional formatting
but here's code that would work.
this assumes that the dates are in column A.
Sub macmarkdate()
Dim lastrow As Long
Dim g As Range
Dim cell As Range
Application.ScreenUpdating = False
Set g = Range(Range("A1"), Range("A1").End(xlDown))
For Each cell In g
If cell.Value < now()-365 Then
cell.Interior.ColorIndex = 46
End If
Next cell

Application.ScreenUpdating = True

End Sub

-----Original Message-----
I am looking to write a macro that will check for a date

range in a group of
cells (for example: today through one year ago today) in

a worksheet. Then
I would like to highlight the cells that fall within this

date range in bold
red. So far, all I get are syntax errors when trying to

write this macro.
Any ideas?
.

  #4   Report Post  
boconnell
 
Posts: n/a
Default


thanks for the tip! but now it's lead to another issue, in that even the
blank cells are highlighted. how do i specify not to format a blank cell?
also, where do you find the colour index numbers? i see that you have red =
46, but is there a listing somewhere that correlates numbers to colours?

" wrote:

hi,
a much easier way would be to use conditional formatting
but here's code that would work.
this assumes that the dates are in column A.
Sub macmarkdate()
Dim lastrow As Long
Dim g As Range
Dim cell As Range
Application.ScreenUpdating = False
Set g = Range(Range("A1"), Range("A1").End(xlDown))
For Each cell In g
If cell.Value < now()-365 Then
cell.Interior.ColorIndex = 46
End If
Next cell

Application.ScreenUpdating = True

End Sub

-----Original Message-----
I am looking to write a macro that will check for a date

range in a group of
cells (for example: today through one year ago today) in

a worksheet. Then
I would like to highlight the cells that fall within this

date range in bold
red. So far, all I get are syntax errors when trying to

write this macro.
Any ideas?
.


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
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
SUMPRODUCT with date range question Rob V Excel Discussion (Misc queries) 1 January 31st 05 03:55 PM
Date and Time Macro m.j.anderson Excel Discussion (Misc queries) 1 December 1st 04 12:35 AM
How can I sum information in a list with a date range? Dave Excel Worksheet Functions 2 November 23rd 04 08:17 PM
HOW TO USE CONDITIONAL FORMATTING FROM ONE RANGE TO ANOTHER RANGE PeggyP Excel Worksheet Functions 2 November 4th 04 07:29 PM


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