Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro to convert date to text

Excel 2003 VB - I need to add code to a macro that compares today's date to
the last time this macro was run, and provides the number of days different
between the two dates.

Can anyone help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro to convert date to text


Add the following code at the beginning of your existing code. It will
create an hidden defined name called "LastRun" containing the date on
which the code was executed.

Dim D As Date
Dim S As String
Dim Nm As Name
On Error Resume Next
Set Nm = ThisWorkbook.Names("LastRun")
If Err.Number < 0 Then
ThisWorkbook.Names.Add "LastRun", Int(Now), False
Else
S = Nm.RefersTo
S = Mid(S, 2)
D = CDate(S)
Debug.Print "Last Run: " & D, "Days between: " & Int(Now) - D
End If
ThisWorkbook.Names.Add "LastRun", Int(Now), False

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Tue, 17 Feb 2009 14:21:01 -0800, Mr. Clean
wrote:

Excel 2003 VB - I need to add code to a macro that compares today's date to
the last time this macro was run, and provides the number of days different
between the two dates.

Can anyone help?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Macro to convert date to text

If it were me, I'd add a named range that contains the last time the macro
was run. Each time the macro is run, I'd pull that value and do the
calculation. After the calculation is done, I'd reset the named range. If
you need more info on this, come back and let us know.
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Mr. Clean" wrote:

Excel 2003 VB - I need to add code to a macro that compares today's date to
the last time this macro was run, and provides the number of days different
between the two dates.

Can anyone help?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro to convert date to text

Thanks for the VERY swift reply. This was my first post.

I need one more thing. I need to write a text message into a cell that
tells the user that the last time this macro was run was more than 90 days
ago.

"Mr. Clean" wrote:

Excel 2003 VB - I need to add code to a macro that compares today's date to
the last time this macro was run, and provides the number of days different
between the two dates.

Can anyone help?

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
how do i convert text to date (mm/yy text to mm/dd/yyyy date)? lindsey Excel Discussion (Misc queries) 1 July 27th 07 10:05 PM
VBA convert day and date from text string to Excel date Max Bialystock[_2_] Excel Programming 5 May 14th 07 04:54 AM
Excel, how do I write a macro to convert the date value to text? airedale girl Excel Programming 1 September 19th 06 04:06 PM
Help: How do I convert a text date into a real date format japorms Excel Worksheet Functions 4 August 2nd 06 06:36 PM
Macro to convert text to date Nortos Excel Worksheet Functions 2 May 11th 05 10:42 AM


All times are GMT +1. The time now is 06:24 PM.

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

About Us

"It's about Microsoft Excel"