Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Find and replace macro

Hi,

I am preparing a template document for use within my organisation which will
be used to populate a monthly report.

The template has formula references to multiple Excel files that are
produced in monthly downloads from our systems.

I want to create a macro so that the user can enter the location of the
existing file in one cell (A2), the location of the new file in another cell
(B2) and then run a macro which does a find and replace of all instances of
A2 with B2. As part of the macro I also want it to update A2 with the data
from B2 and clear out the data in B2.
There are multiple links that will be updated so it would good to work out a
way that can update multiple links (e.g. A2 with B2, A3 with B3, A4 with B4
etc) in one go.

Could one of you good people help me out?

Thanks

Ed
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Find and replace macro

Consider:

Sub suby()
Dim s As String, t As String, rr As Range
s = Range("A2").Value
t = Range("B2").Value
Set rr = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormu las)
For Each r In rr
r.Formula = Replace(r.Formula, s, t)
Next
Range("A2").Value = Range("B2").Value
Range("B2").Clear
End Sub
--
Gary''s Student - gsnu200825
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Find and replace macro

Hi,

That seems to do the job nicely. The one small problem I have is that once I
run the macro I cant undo any changes made (ctrl+z) - is that standard for
macros or could we add / change some code to allow undo to work again?

Thanks

Ed

"Gary''s Student" wrote:

Consider:

Sub suby()
Dim s As String, t As String, rr As Range
s = Range("A2").Value
t = Range("B2").Value
Set rr = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormu las)
For Each r In rr
r.Formula = Replace(r.Formula, s, t)
Next
Range("A2").Value = Range("B2").Value
Range("B2").Clear
End Sub
--
Gary''s Student - gsnu200825

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Find and replace macro

Undo will not work.
--
Gary''s Student - gsnu200825


"edeaston" wrote:

Hi,

That seems to do the job nicely. The one small problem I have is that once I
run the macro I cant undo any changes made (ctrl+z) - is that standard for
macros or could we add / change some code to allow undo to work again?

Thanks

Ed

"Gary''s Student" wrote:

Consider:

Sub suby()
Dim s As String, t As String, rr As Range
s = Range("A2").Value
t = Range("B2").Value
Set rr = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormu las)
For Each r In rr
r.Formula = Replace(r.Formula, s, t)
Next
Range("A2").Value = Range("B2").Value
Range("B2").Clear
End Sub
--
Gary''s Student - gsnu200825

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 to Find and Replace R Storey Excel Discussion (Misc queries) 6 December 6th 06 07:04 PM
Macro to Find & Replace [email protected] Excel Worksheet Functions 2 September 14th 06 07:17 PM
Macro: Find and replace Bertie Excel Discussion (Misc queries) 1 May 29th 06 02:01 PM
find&replace macro Elainey Excel Worksheet Functions 0 January 6th 06 09:20 PM
Find & Replace in VB macro JackC Excel Discussion (Misc queries) 1 August 24th 05 09:22 PM


All times are GMT +1. The time now is 04:12 AM.

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"