Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default How to Get Date of Each Cell....

I need to highlight each cell in a column that satisfies anything earlier
than the current date+1 (e.g. anything earlier than 2006-06. June '06). They
have to be processed as strings, thus the fist two lines.

s_current = Format(DateSerial(Year(Date), Month(Date), Day(Date)), "yyyy-mm")
s_past = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "yyyy-mm")
Application.Goto Reference:="MP_Start"
myMPStartColumn = ActiveCell.Column
Set rng = ActiveCell.EntireRow
For Each cell In rng
If s_current = s_past Then
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next

I know this isn't doing anything (I need to do something with "cell"). How
to I evalutate each cell in the colume and compare it against the current
date, thus being able to highlight, given that criteria?

Please help!

Thanks,
Mark
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default How to Get Date of Each Cell....

Have you tried conditional formatting?

"formula is" =DateValue(A1)<(today()+1)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default How to Get Date of Each Cell....

Brian,

I get an error when i enter this:

s_current = Format(DateSerial(Year(Date), Month(Date), Day(Date)),
"yyyy-mm")
s_past = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "yyyy-mm")
Application.Goto Reference:="MP_Start"
myMPStartColumn = ActiveCell.Column
Set rng = ActiveCell.EntireRow
For Each cell In rng
If DateValue(cell) <= s_past Then
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next

I think we're getting closer. I really really appreciate your help!!!

-m

"Brian Taylor" wrote:

Have you tried conditional formatting?

"formula is" =DateValue(A1)<(today()+1)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default How to Get Date of Each Cell....

I get a type mismatch error. Is this because of the string thing?

Thanks,
Mark

"mvyvoda" wrote:

Brian,

I get an error when i enter this:

s_current = Format(DateSerial(Year(Date), Month(Date), Day(Date)),
"yyyy-mm")
s_past = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "yyyy-mm")
Application.Goto Reference:="MP_Start"
myMPStartColumn = ActiveCell.Column
Set rng = ActiveCell.EntireRow
For Each cell In rng
If DateValue(cell) <= s_past Then
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next

I think we're getting closer. I really really appreciate your help!!!

-m

"Brian Taylor" wrote:

Have you tried conditional formatting?

"formula is" =DateValue(A1)<(today()+1)


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default How to Get Date of Each Cell....

Conditional formatting would be much simpler than writing code. Have
you already tried that option?

You would need to change your code a little to make it work. Here is
some untested code to take a look at:

Sub test()
Set rng = ActiveCell.EntireRow
For Each Cell In rng
If DateValue(Cell.Value) <= (Now() - 1) Then
With Cell.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default How to Get Date of Each Cell....

conditional formatting it is! it works this way, but it's weird because i
can't change the cells back to no color... even manually.

is this a side affect of running conditional formatting via macro?

thanks,
mark


"Brian Taylor" wrote:

Conditional formatting would be much simpler than writing code. Have
you already tried that option?

You would need to change your code a little to make it work. Here is
some untested code to take a look at:

Sub test()
Set rng = ActiveCell.EntireRow
For Each Cell In rng
If DateValue(Cell.Value) <= (Now() - 1) Then
With Cell.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next
End Sub


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default How to Get Date of Each Cell....

You should be able to change the cells back to no fill. It should not
be a permanent fill change. The only thing that would keep you from
changing the cell color back is if you had put the procedure in the
selection change event. In which it would keep on applying the change
everytime you select a new cell.

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
Excel 2003 make 1 date cell automatically change another date cell Scotty Excel Worksheet Functions 4 April 22nd 10 09:01 AM
date in Cell to change colors if the date is beyond today's date Pete Elbert Excel Discussion (Misc queries) 2 June 6th 09 06:31 AM
Split date from date time cells dd/mm/yyyy hh:mm. New cell dd/mm/y nigeo Excel Discussion (Misc queries) 3 April 1st 09 09:38 PM
Automatically update a cell with a date based on anther cells date GPR GUY Excel Discussion (Misc queries) 2 November 3rd 08 03:57 PM
Date Turns Green 90-Days before the date shown in cell ajaminb Excel Worksheet Functions 7 September 28th 08 11:36 PM


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