Find All cells in workbook containing specific formula, convert to values.

LenPL

New Member
Joined
Aug 1, 2013
Messages
17
All,

I am trying to find a method for converting all cells in entire workbook starting with the formula "=cc." to values.

This is what I have so far.

Code:
Sub
    Do Until IsNotFound
    
    Cells.Find(What:="=cc.", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
        
    
    Selection.Copy
    
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Loop
    
        
End Sub

There are two issues at present, it only works on the current worksheet, and secondly it returns a Run-time '91' Error on completion of the sheet (altough I can live with this issue).

Thank you in advance.

Len
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
give this a try

Code:
Sub SearchFormula()
Dim mySearch()
Dim i As Integer
Dim c As Range
Dim ws As Worksheet
mySearch = Array("cc.")
For i = 0 To UBound(mySearch)
 For Each ws In Worksheets
 On Error Resume Next
 With ws.UsedRange.SpecialCells(xlCellTypeFormulas)
     Set c = .Find(mySearch(i), LookIn:=xlFormulas)
     Do
         c.Value = c.Value
         Set c = .FindNext(c)
     Loop Until c Is Nothing
 End With
 Next ws
Next i
    
End Sub
 
Upvote 0
Hi Len

Firstly, the issue with it only running in one worksheet you can do the following:

Before the do enter the following:


"Dim a as integer

For a = 1 to Sheets.Count
Sheets(a).Select
With Worksheet do
Range("A1").Select"

And then after the loop
"End with
Next"

Also try and define your range to run through. Otherwise your coding might be heavy.

Hope this helps
 
Upvote 0
give this a try

Code:
Sub SearchFormula()
Dim mySearch()
Dim i As Integer
Dim c As Range
Dim ws As Worksheet
mySearch = Array("cc.")
For i = 0 To UBound(mySearch)
 For Each ws In Worksheets
 On Error Resume Next
 With ws.UsedRange.SpecialCells(xlCellTypeFormulas)
     Set c = .Find(mySearch(i), LookIn:=xlFormulas)
     Do
         c.Value = c.Value
         Set c = .FindNext(c)
     Loop Until c Is Nothing
 End With
 Next ws
Next i
    
End Sub

HippeHacker,

I have no idea what you have done, but it seems to work like a dream (could be faster)! Thank you very much.

Len
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top