Find and Replace with cell Value

lynxbci

Board Regular
Joined
Sep 22, 2004
Messages
201
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi,
I have multiple worksheets with cells, some of which contain formulas that link it to an outside data source. The formulas are not always starting with the same text. But always contain "cc.f" somehwere in the formula.

I have tried in vane to write a macro that looks at all cells to see if they contain "cc.f" anywhere and if they do replace the cell with its value. The issue with this code is that it replaces any cell with anything in it with the cell value.

This is the main part of the code i tried (if it helps)

Code:
For Each ws In ActiveWorkbook.Worksheets
     On Error Resume Next
     For Each c In ws.UsedRange.SpecialCells(xlCellTypeFormulas)
           
     Set foundcog = c.Find(What:="cc.f", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
     :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
     False, SearchFormat:=False).Activate
                                      
     If UCase(TypeName(foundcog)) <> UCase("Nothing") Then
        ActiveCell.Replace What:="*", Replacement:=ActiveCell.Text, LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
      End If
                    
      Cells.FindNext(After:=ActiveCell).Activate
                    
   Next
   On Error GoTo 0
Next ws

Please help me to solve this one

Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi,
I have multiple worksheets with cells, some of which contain formulas that link it to an outside data source. The formulas are not always starting with the same text. But always contain "cc.f" somehwere in the formula.

I have tried in vane to write a macro that looks at all cells to see if they contain "cc.f" anywhere and if they do replace the cell with its value. The issue with this code is that it replaces any cell with anything in it with the cell value.

This is the main part of the code i tried (if it helps)

Code:
For Each ws In ActiveWorkbook.Worksheets
     On Error Resume Next
     For Each c In ws.UsedRange.SpecialCells(xlCellTypeFormulas)
 
     Set foundcog = c.Find(What:="cc.f", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
     :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
     False, SearchFormat:=False).Activate
 
     If UCase(TypeName(foundcog)) <> UCase("Nothing") Then
        ActiveCell.Replace What:="*", Replacement:=ActiveCell.Text, LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
      End If
 
      Cells.FindNext(After:=ActiveCell).Activate
 
   Next
   On Error GoTo 0
Next ws

Please help me to solve this one

Thanks


TRY THIS

Code:
Function clearit()
Dim c As Range
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
     On Error Resume Next
     For Each c In ws.UsedRange.SpecialCells(xlCellTypeFormulas)
           
     If InStr(1, c.Formula, "CC.F") > 0 Then
        c.Value = c.Value
     End If
     
                            
     Next c
   On Error GoTo 0
Next ws
End Function

Mostly yours but less
 
Upvote 0
Fantastic

Thansk so much, simple and effective.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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