Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Find & Replace w/ Name Changes


I have a workbook that I use month to month named "Report
MTH YY" This month the report is named "Report Jul 04".
Next month the report will be renamed "Report Aug 04",
then "Report Sep 04" etc.

I have formulas that reference last months report. As
simple as " ='[REPORT Jun 04.xls]Sheet 1'!A1". Next
month in "Report Aug 04" I want the formula to reference
the Jul report i.e. ='[REPORT Jul 04.xls]Sheet 1'!A1" .

I am looking for a way to automate the process rather
than manually using "Find & Replace", but I do not know
how to get the month names to change automatically.

More specifically, I am looking for a way to create a
macro using "Find & Replace" that will find and replace
the month name. So I have;

Cells.Select
Selection.Replace What:="Month(Now()-1",
Replacement:="Month (Now()", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False

Obviously it does not work. I need to know how to create
the "What:=" and the "Replacement:=" to -
What:= "last month (Jun)"
Replacement:= this month (Jul)

Thanks to Tom Ogilvy for the solution using "Indirect",
however the workbook that the data is generated from is
never open, but it is always in the same directory.


Thanks for any additional help.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Find & Replace w/ Name Changes

Changing the formula with replace would be the "goofy" way to do it.

Turn on the macro recorder and then do

Edit=Links=Change Source and change the source to "new" last month's
workbook.

That will give you the code you need. You can then modify it to make it
dynamic.

to format the date to match your file naming convention

Sub Tester2()
Dim dt As Date, oldDt As Date
Dim oldoldDt As Date
Dim sOldMonthandYear As String
dt = Date
oldDt = DateSerial(Year(dt), Month(dt) - 1, 1)
oldoldDt = DateSerial(Year(oldDt), Month(oldDt) - 1, 1)
sCurrentLinkName = "Report " & Format(oldoldDt, "mmm yy") & ".xls"
sOldMonthandYear = "Report " & Format(oldDt, "mmm yy") & ".xls"
Debug.Print dt, oldDt, oldoldDt
Debug.Print sCurrentLinkName, sOldMonthandYear
End Sub

produces:
7/20/2004 6/1/2004 5/1/2004
Report May 04.xls Report Jun 04.xls

So the current link is to the file named for two months ago and you want to
change it to the file name for one month ago.
--
Regards,
Tom Ogilvy




"ronbo" wrote in message
...

I have a workbook that I use month to month named "Report
MTH YY" This month the report is named "Report Jul 04".
Next month the report will be renamed "Report Aug 04",
then "Report Sep 04" etc.

I have formulas that reference last months report. As
simple as " ='[REPORT Jun 04.xls]Sheet 1'!A1". Next
month in "Report Aug 04" I want the formula to reference
the Jul report i.e. ='[REPORT Jul 04.xls]Sheet 1'!A1" .

I am looking for a way to automate the process rather
than manually using "Find & Replace", but I do not know
how to get the month names to change automatically.

More specifically, I am looking for a way to create a
macro using "Find & Replace" that will find and replace
the month name. So I have;

Cells.Select
Selection.Replace What:="Month(Now()-1",
Replacement:="Month (Now()", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False

Obviously it does not work. I need to know how to create
the "What:=" and the "Replacement:=" to -
What:= "last month (Jun)"
Replacement:= this month (Jul)

Thanks to Tom Ogilvy for the solution using "Indirect",
however the workbook that the data is generated from is
never open, but it is always in the same directory.


Thanks for any additional 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
Find & Replace: find part cell, replace whole cell katy Excel Worksheet Functions 3 April 3rd 23 01:20 PM
Find and Replace - Replace with Blank Space Studebaker Excel Discussion (Misc queries) 4 April 3rd 23 10:55 AM
where to put results of find operation in find and replace functio DEP Excel Worksheet Functions 5 November 15th 06 07:52 PM
find and replace - replace data in rows to separated by commas msdker Excel Worksheet Functions 1 April 15th 06 01:00 AM
find replace cursor default to find box luffa Excel Discussion (Misc queries) 0 February 3rd 05 12:11 AM


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