Solved

Excel Find and Replace Issues

Posted on 2011-03-21
16
902 Views
Last Modified: 2012-06-21
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
Comment
Question by:Amerilab
16 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35180841
You shouldn't get any prompts if the replacement formula is correct - does the 2011_2012 sheet exist?
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 35180850
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
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35180853
CrossOver.

Sid
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:Amerilab
ID: 35180937
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
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35180971
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
 

Author Comment

by:Amerilab
ID: 35180990
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
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35181024
>>>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
 
LVL 5

Expert Comment

by:Kannan K
ID: 35181149
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
 

Author Comment

by:Amerilab
ID: 35181175
Is there a way to do run this MACRO on other workbooks?  


Set ws = "what ever the current workbook is"
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35181191
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
 

Author Comment

by:Amerilab
ID: 35181211
Kannan,

That way does show the formulas, but I still get the message to update each cell.
0
 

Author Comment

by:Amerilab
ID: 35181228
I believe it did, however these excel sheets are not something we would like a Macro attached to.  
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35181239
So do you want to use a VBA Method or Manual Method?

Sid
0
 

Author Comment

by:Amerilab
ID: 35181271
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
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35181460
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
 

Author Comment

by:Amerilab
ID: 35182496
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

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question