Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Comparing old date to now() and writing out text message in column

I'm new to Excel programming & I'm working on a [stock purchase]
spreadsheet trying to compare a column of dates (range named
"acquired") to the current date. Any acquired date over 365 days
should write a text message saying "long" in the adjacent column range
named "holding". Acquired dates less that 365 needs to write "short".

Thanks for your help.

Joe
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Comparing old date to now() and writing out text message in column

try this. Of course, modify to suit. Assumes dates in col A

Sub comparedate()
For Each c In Range("a1:a3")
If c + 365 Now Then c.Offset(, 1) = "Long"
If c + 365 < Now Then c.Offset(, 1) = "Short"
Next
End Sub

"Joeyej" wrote in message
om...
I'm new to Excel programming & I'm working on a [stock purchase]
spreadsheet trying to compare a column of dates (range named
"acquired") to the current date. Any acquired date over 365 days
should write a text message saying "long" in the adjacent column range
named "holding". Acquired dates less that 365 needs to write "short".

Thanks for your help.

Joe



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Comparing old date to now() and writing out text message in column

if c + 365 is greater than now, then c was acquired less than 365 days ago,
so that should be "short" shouldn't it?

Probably should allow for exactly 365 days as well. (although unspecified
by the OP). Since Now has a time value, I guess it is unlikely to hit an
exactly 365 days situation.

--
Regards,
Tom Ogilvy

Don Guillett wrote in message
...
try this. Of course, modify to suit. Assumes dates in col A

Sub comparedate()
For Each c In Range("a1:a3")
If c + 365 Now Then c.Offset(, 1) = "Long"
If c + 365 < Now Then c.Offset(, 1) = "Short"
Next
End Sub

"Joeyej" wrote in message
om...
I'm new to Excel programming & I'm working on a [stock purchase]
spreadsheet trying to compare a column of dates (range named
"acquired") to the current date. Any acquired date over 365 days
should write a text message saying "long" in the adjacent column range
named "holding". Acquired dates less that 365 needs to write "short".

Thanks for your help.

Joe





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Comparing old date to now() and writing out text message in column

Yeah, I guess OP can change to suit.

"Tom Ogilvy" wrote in message
...
if c + 365 is greater than now, then c was acquired less than 365 days

ago,
so that should be "short" shouldn't it?

Probably should allow for exactly 365 days as well. (although unspecified
by the OP). Since Now has a time value, I guess it is unlikely to hit an
exactly 365 days situation.

--
Regards,
Tom Ogilvy

Don Guillett wrote in message
...
try this. Of course, modify to suit. Assumes dates in col A

Sub comparedate()
For Each c In Range("a1:a3")
If c + 365 Now Then c.Offset(, 1) = "Long"
If c + 365 < Now Then c.Offset(, 1) = "Short"
Next
End Sub

"Joeyej" wrote in message
om...
I'm new to Excel programming & I'm working on a [stock purchase]
spreadsheet trying to compare a column of dates (range named
"acquired") to the current date. Any acquired date over 365 days
should write a text message saying "long" in the adjacent column range
named "holding". Acquired dates less that 365 needs to write "short".

Thanks for your help.

Joe







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
writing text to different cell after comparing tracktraining Excel Worksheet Functions 2 February 9th 09 11:47 PM
COUNTIF: 2 criteria: Date Range Column & Text Column MAC Excel Worksheet Functions 14 September 16th 08 04:39 PM
Warning message if one column contains any text and another column is blank Dileep Chandran Excel Worksheet Functions 12 October 30th 06 07:50 PM
Date format/Writing to a file problem clayton Excel Discussion (Misc queries) 0 August 8th 06 01:31 AM
help with VBA code re comparing cells and generating message with detailed info Ross[_5_] Excel Programming 2 July 13th 03 01:19 AM


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