Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Replacing via macro

Two questions:

1) I am trying to replace 2008 within several formulas with 2009. Both
2008 and 2009 are worksheet names and appear in the formulas such as the
following:

[Paychecks.xls]2008'!$B$10 (part of formula)

I have looked at two different ways and need help on choosing the best
method AND if I need to adjust the macro code to make it work correctly.

Method 1:
Range("S5:X705").Replace _
What:="2008", Replacement:="2009", _
SearchOrder:=xlByRows, MatchCase:=True

Not sure if quotes are neede in the above example.

Method 2:
Range("S5:X705").Select
For Each cell In Selection
cell.Formula = Replace(cell.Formula, "2008", "2009")
Next cell


Question 2) I have executed the code shown in Method 2. Problem is that
since the formula references another workbook, it opens a window (displaying
contents of folder (directory) asking to update the workbook referenced in
the formula. How can I stop that part from happening?

Thanks,
Les
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Replacing via macro

When I get that dialog box, it means that the filename (or sheet within that
workbook) I changed to doesn't really exist. So excel is asking where the real
file (or worksheet) is.

Are you sure that the filenames only difference by that year string?

===
Once you've corrected that problem, then I would think the edit|Replace version
would be much quicker than looping through all the cells.

WLMPilot wrote:

Two questions:

1) I am trying to replace 2008 within several formulas with 2009. Both
2008 and 2009 are worksheet names and appear in the formulas such as the
following:

[Paychecks.xls]2008'!$B$10 (part of formula)

I have looked at two different ways and need help on choosing the best
method AND if I need to adjust the macro code to make it work correctly.

Method 1:
Range("S5:X705").Replace _
What:="2008", Replacement:="2009", _
SearchOrder:=xlByRows, MatchCase:=True

Not sure if quotes are neede in the above example.

Method 2:
Range("S5:X705").Select
For Each cell In Selection
cell.Formula = Replace(cell.Formula, "2008", "2009")
Next cell

Question 2) I have executed the code shown in Method 2. Problem is that
since the formula references another workbook, it opens a window (displaying
contents of folder (directory) asking to update the workbook referenced in
the formula. How can I stop that part from happening?

Thanks,
Les


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Replacing via macro

I have the budget and paycheck workbook on a flash drive that I keep with me
and edit the data as needed. When I am home, I update the copies on the
desktop. I use the workbooks on the desktop to update each other and then
copy back to the flash drive. That is why it cannot find the file.

Les


"Dave Peterson" wrote:

When I get that dialog box, it means that the filename (or sheet within that
workbook) I changed to doesn't really exist. So excel is asking where the real
file (or worksheet) is.

Are you sure that the filenames only difference by that year string?

===
Once you've corrected that problem, then I would think the edit|Replace version
would be much quicker than looping through all the cells.

WLMPilot wrote:

Two questions:

1) I am trying to replace 2008 within several formulas with 2009. Both
2008 and 2009 are worksheet names and appear in the formulas such as the
following:

[Paychecks.xls]2008'!$B$10 (part of formula)

I have looked at two different ways and need help on choosing the best
method AND if I need to adjust the macro code to make it work correctly.

Method 1:
Range("S5:X705").Replace _
What:="2008", Replacement:="2009", _
SearchOrder:=xlByRows, MatchCase:=True

Not sure if quotes are neede in the above example.

Method 2:
Range("S5:X705").Select
For Each cell In Selection
cell.Formula = Replace(cell.Formula, "2008", "2009")
Next cell

Question 2) I have executed the code shown in Method 2. Problem is that
since the formula references another workbook, it opens a window (displaying
contents of folder (directory) asking to update the workbook referenced in
the formula. How can I stop that part from happening?

Thanks,
Les


--

Dave Peterson

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
Macro replacing links [email protected] Excel Discussion (Misc queries) 1 August 10th 06 04:08 PM
replacing macro? beatrice25 Excel Discussion (Misc queries) 5 June 21st 06 01:33 AM
Macro help:replacing figures phil2006[_5_] Excel Programming 1 June 5th 06 02:59 PM
Macro help:replacing figures phil2006 Excel Discussion (Misc queries) 0 June 5th 06 02:40 PM
In a Macro replacing $x with ($x + i) gives x+1 not $x+1 as expe. zorro New Users to Excel 0 March 3rd 06 05:28 AM


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