Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Macro to FIND/REPLACE

I have written a macro to initialize a worksheet that is copied. There are
three elements that need to be changed throughout the worksheet for the
upcoming year:

1) Change caption on commandbuttons to show 2009
2) Change the date for each of the 12 budgets to correct year
3) change the 2008 to 2009 in the formulas in some of the cells.

Elements 1 and 2 are working, but I cannot figure out how to look in a
formula in a cell for the value 2008 and change it to 2009.

This is what I had, but it did not work:

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

I copied this from a website I found on replacing a value.

Thanks for your help,
Les

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,805
Default Macro to FIND/REPLACE

You need to replace in Cell.Formula not Cell.Value
Try
Sub test()
Range("S5:X705").Select
For Each cell In Selection
cell.Formula = Replace(cell.Formula, "2008", "2009")
Next cell
End Sub

Try the sample code below to understand
Sub t()
Dim str As String
MsgBox Range("A1").Formula
str = Range("A1").Formula
str = Replace(str, "2008", "2009")
Range("A1").Formula = str
MsgBox Range("A1").Formula
End Sub
"WLMPilot" wrote:

I have written a macro to initialize a worksheet that is copied. There are
three elements that need to be changed throughout the worksheet for the
upcoming year:

1) Change caption on commandbuttons to show 2009
2) Change the date for each of the 12 budgets to correct year
3) change the 2008 to 2009 in the formulas in some of the cells.

Elements 1 and 2 are working, but I cannot figure out how to look in a
formula in a cell for the value 2008 and change it to 2009.

This is what I had, but it did not work:

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

I copied this from a website I found on replacing a value.

Thanks for your help,
Les

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 and Replace in a Macro [email protected] Excel Programming 4 December 1st 07 04:27 AM
Find & Replace and Find & Insert macro help needed RS Excel Programming 2 January 29th 07 07:35 AM
Macro to Find & Replace [email protected] Excel Worksheet Functions 2 September 14th 06 07:17 PM
Using Find and Replace to replace " in a macro snail30152 Excel Programming 1 April 13th 06 11:58 PM
A Macro to Do Find and Replace Eric Excel Programming 2 February 27th 04 12:22 AM


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