0

I have the big Excel with a lot of formulas. I would like to save this Excel as values but only for some formulas not for all.

I use this VBA script - but this replaces all formulas by values. How can I replace for example only all cells which contain formula SUM - maybe which contain =SUM(

Sub Saveasvalue()
    Dim wsh As Worksheet
    For Each wsh In ThisWorkbook.Worksheets
        wsh.Cells.Copy
        wsh.Cells.PasteSpecial xlPasteValues
    Next
    Application.CutCopyMode = False
End Sub

1 Answer 1

1

You will have to add a checking condition like below to test if the cell contains SUM formula.

Sub Saveasvalue()
    Dim wsh As Worksheet
    Dim rng As Range
    For Each wsh In ThisWorkbook.Worksheets
        For Each rng In wsh.UsedRange
            If InStr(1, rng.Formula, "SUM(", vbTextCompare) > 0 Then
                rng.Value = rng.Value
            End If
        Next rng
    Next
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.