Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
LWhite
 
Posts: n/a
Default how to alter the date within a macro

Hello,

I was trying to create an archive function on a workbook.
I have a formula throughout the workbook that is based on
the current date using NOW(). I went in a recorded a
macro of replacing the NOW() with last years date. How
can I set this so that I can have the user push a button
to archive the sheet and have the year based on the
current date? I want to change the replacement to an
argument that gives the year -1 at the time of clicking
the archive button. The current recorded code follows.

Thank You
LWhite

Cells.Replace What:="NOW()", Replacement:="Date
(2004,12,31)", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False
Application.CutCopyMode = False
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

How about something like:

Dim myStr As String
myStr = "date(" & Year(Date) - 1 & ",12, 31)"

Cells.Replace What:="NOW()", Replacement:=myStr, _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
searchFormat:=False, ReplaceFormat:=False

LWhite wrote:

Hello,

I was trying to create an archive function on a workbook.
I have a formula throughout the workbook that is based on
the current date using NOW(). I went in a recorded a
macro of replacing the NOW() with last years date. How
can I set this so that I can have the user push a button
to archive the sheet and have the year based on the
current date? I want to change the replacement to an
argument that gives the year -1 at the time of clicking
the archive button. The current recorded code follows.

Thank You
LWhite

Cells.Replace What:="NOW()", Replacement:="Date
(2004,12,31)", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False
Application.CutCopyMode = False


--

Dave Peterson
  #3   Report Post  
 
Posts: n/a
Default

Thank you very much. That really helped.

LWhite
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 updates from worksheet to chart & changes date to a date series! Help!! Jayjg Charts and Charting in Excel 2 January 22nd 05 03:00 PM
Date formula Robyn Bellanger Excel Discussion (Misc queries) 2 December 16th 04 12:41 AM
Problem with Date format from VBA code twig Excel Discussion (Misc queries) 3 December 7th 04 06:01 PM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
Date and Time Macro m.j.anderson Excel Discussion (Misc queries) 1 December 1st 04 12:35 AM


All times are GMT +1. The time now is 09:07 AM.

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"