Function to replace formulas with values

lynxbci

Board Regular
Joined
Sep 22, 2004
Messages
201
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi,
I have a workbook, multiple sheets, and within each sheet there are multiple cells with formulas in. I want to write a function to replace any cell which has a formula, with the value in the cell. Tried find and replace macro, but seems very messy. Any suggestions please?
Thanks in advance
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You can't use a function, but here's a Sub to try:

Code:
Sub Test()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        With ws
            .Cells.Copy
            .Range("A1").PasteSpecial xlPasteValues
        End With
    Next ws
End Sub
 
Upvote 0
Try

Code:
Sub FtoVal()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    On Error Resume Next
    With ws.UsedRange.SpecialCells(xlCellTypeFormulas)
        .Value = .Value
    End With
    On Error GoTo 0
Next ws
End Sub
 
Upvote 0
Hi,

Can i thank you, and add a slight change, I only want to replace formulas that begin with "=cc.*" and leave all other formulas in tact.

Thanks again
 
Upvote 0
Try

Code:
Sub FtoVal()
Dim ws As Worksheet, c As Range
For Each ws In ActiveWorkbook.Worksheets
    On Error Resume Next
    For Each c In ws.UsedRange.SpecialCells(xlCellTypeFormulas)
        If c.Formula Like "=cc.*" Then c.Value = c.Value
    End With
    On Error GoTo 0
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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