Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove formulas from sheet but keep their calculated values [closed]

Tags:

excel

vba

Can you please let me know how I can remove all formulas from a sheet but keep the results of calculations in excel VBA?

I have a sheet called map which has lots of calculation columns there now I would like to remove all of this formulas but still keep the result to save into a new sheet.

like image 212
Behseini Avatar asked Dec 19 '13 01:12

Behseini


People also ask

How do you remove formula in Excel and keep value without copying?

1. Select the cells with formulas you want to remove but keep results, press Ctrl + C keys simultaneously to copy the selected cells. 2. Then click Home > Paste > Values.


1 Answers

Way 1 (Courtesy @rdhs)

Sub Sample()
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Sheets("DTMGIS")

    ws.UsedRange.Value = ws.UsedRange.Value
End Sub

Way 2 Using Copy - PasteSpecial - Values

Sub Sample()
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Sheets("DTMGIS")

    With ws.UsedRange
        .Copy
        .PasteSpecial Paste:=xlPasteValues, _
        Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
    End With
End Sub

Way 3 Using SpecialCells

Sub Sample()
    Dim ws As Worksheet
    Dim rng As Range

    Set ws = ThisWorkbook.Sheets("DTMGIS")

    On Error Resume Next
    Set rng = ws.Cells.SpecialCells(xlCellTypeFormulas)
    On Error GoTo 0

    If Not rng Is Nothing Then
        rng.Value = rng.Value
    End If
End Sub
like image 109
Siddharth Rout Avatar answered Nov 15 '22 22:11

Siddharth Rout