A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Macro for Date If Statement



 
 
Thread Tools Display Modes
  #1  
Old May 7th, 2010, 05:28 AM posted to microsoft.public.word.newusers
ray
external usenet poster
 
Posts: 475
Default Macro for Date If Statement

I have a column of Dates, need the Macro to look at all the date in the
column and compare to the current date and if the date in the column is more
that 365 days old want to turn the date in the column GREEN! Can this be
done? Currently there are over 500 dates in the column.

Thanks for your help
Ray
  #2  
Old May 7th, 2010, 06:32 AM posted to microsoft.public.word.newusers
Graham Mayor
external usenet poster
 
Posts: 18,297
Default Macro for Date If Statement

Column? Are the dates in a table? If so then the following will work (with
column1) of the table containing the cursor

Dim oCell As Cell
Dim oRng As Range
With Selection.Tables(1)
For Each oCell In .Columns(1).Cells
Set oRng = oCell.Range
oRng.End = oRng.End - 1
If DateDiff("d", oRng, Now) 365 Then
oRng.Font.Color = wdColorGreen
End If
Next oCell
End With

If the dates are each to a paragraph then select the paragraphs and run the
following macro

Dim oPara As Paragraph
Dim oRng As Range
For Each oPara In Selection.Paragraphs
Set oRng = oPara.Range
oRng.End = oRng.End - 1
If DateDiff("d", oRng, Now) 365 Then
oRng.Font.Color = wdColorGreen
End If
Next oPara

http://www.gmayor.com/installing_macro.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





"Ray" wrote in message
...
I have a column of Dates, need the Macro to look at all the date in the
column and compare to the current date and if the date in the column is
more
that 365 days old want to turn the date in the column GREEN! Can this be
done? Currently there are over 500 dates in the column.

Thanks for your help
Ray



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:06 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.