Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 934
  • Last Modified:

Excel Find and Replace Issues

I have to replace formulas in Excel from 2010_2012 to 2011_2012.  Sounds simple enough right?
For whatever reasons Excel wants me to save/update each individual cell while it tries to replace them.  Since I have over 100,000 replacements to make across a bunch of sheets that won't fly.

Is there a way to use find and replace so it only worries about replacing the formulas and not saving each cell.   Yes I have selected all cells to be replaced at once, still the same problem.


Thanks.
0
Amerilab
Asked:
Amerilab
1 Solution
 
Rory ArchibaldCommented:
You shouldn't get any prompts if the replacement formula is correct - does the 2011_2012 sheet exist?
0
 
SiddharthRoutCommented:
Untested

Try this

Sub Sample()
    Dim oRange As Range, aCell As Range, bCell As Range
    Dim ws As Worksheet
    Dim ExitLoop As Boolean
    Dim SearchString As String, ReplaceString As String
    
    On Error GoTo Err
    
    '~~> Change this to the respective Sheet
    Set ws = Sheets("Sheet1")
    
    Set oRange = ws.Cells

    SearchString = "2010_2012"
    ReplaceString = "2011_2012"
    
    Set aCell = oRange.Find(What:=SearchString, LookIn:=xlFormulas, _
                LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False)
    
    If Not aCell Is Nothing Then
        Set bCell = aCell
        aCell.Formula = Replace(aCell.Formula, SearchString, ReplaceString)
        Do While ExitLoop = False
            Set aCell = oRange.FindNext(After:=aCell)

            If Not aCell Is Nothing Then
                If aCell.Address = bCell.Address Then Exit Do
                aCell.Formula = Replace(aCell.Formula, SearchString, ReplaceString)
            Else
                ExitLoop = True
            End If
        Loop
    End If
    
    MsgBox "Done"
    
    Exit Sub
Err:
    MsgBox Err.Description
End Sub

Open in new window


Sid
0
 
SiddharthRoutCommented:
CrossOver.

Sid
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
AmerilabAuthor Commented:
Before I try anything I forgot to mention that I copied this folder from last years and renamed it to this years.  

Example:  Budgets 2010_2011  was copied and pasted then renamed to Budgets 2011_2012.

Now I am trying to update the formulas in the copied folder to 2011_2012.  

The dumbest thing is when I use the find a replace and put quotes in the replace part it goes through the whole sheet with out asking for a save.  



Untitled.png
0
 
SiddharthRoutCommented:
If You manually do it, and if the folder doesn't exist then it will prompt you. Hence use the code that I gave above and ensure that the replacement string is correct.

Sid
0
 
AmerilabAuthor Commented:
One more thing,  I guess it's not asking to save it, but update the values.  It's looking for a sheet to pull it from, I'd rather skip this and get the formulas updated first.  If there is a way please help.

Thank you.
0
 
SiddharthRoutCommented:
>>>One more thing,  I guess it's not asking to save it, but update the values.  It's looking for a sheet to pull it from, I'd rather skip this and get the formulas updated first.  If there is a way please help.

I already gave you the code ;) See above

Sid
0
 
Kannan KManager - EngineeringCommented:
Hi,

if you want to replace the string in formulas, you can't do directly, you will have to check the Option in option dialog window ==> Advanced ==> Show formulas in cells instead of their calculated results.

then come to your sheet, now you can do your find and replace, then resume back the formula settings.

refer the image [excel 2010]

KK.
EditExcelFormula.png
0
 
AmerilabAuthor Commented:
Is there a way to do run this MACRO on other workbooks?  


Set ws = "what ever the current workbook is"
0
 
SiddharthRoutCommented:
Amerilab: First things first :)

1) Did you try it and did it work?

>>>Is there a way to do run this MACRO on other workbooks?

2) Yes, However, I will come to this once you answer the above question. :)

Sid
0
 
AmerilabAuthor Commented:
Kannan,

That way does show the formulas, but I still get the message to update each cell.
0
 
AmerilabAuthor Commented:
I believe it did, however these excel sheets are not something we would like a Macro attached to.  
0
 
SiddharthRoutCommented:
So do you want to use a VBA Method or Manual Method?

Sid
0
 
AmerilabAuthor Commented:
The way our CFO showed me how to do this was with the find and replace feature.  It used to work, like I said with

FIND:                 2010_2011
REPLACE :        "2011_2012"

But it adds the quotes to the formula too, but now when I hit "replace all" it still goes one cell at a time without the prompt for update.  
0
 
SiddharthRoutCommented:
If you are doing it manually

1) In the replace you do not need the quotes
2) Select "Look in In Formulas" rather that in Values

See how the code above looks in formulas rather than values.

Sid
0
 
AmerilabAuthor Commented:
The problem was right in my face the whole time.   I needed to update the links for each workbook.  
Thank you for all your help today.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now