Removing formulas with VBA in excel also deleting values

CRHAAG

New Member
Joined
Jul 3, 2014
Messages
46
I am trying to remove all of the formulas from various sheets and just leave the values. I have tried to do this with VBA in a few different ways(below) but with each of them there are always some values that just come back as blank. Has anybody experienced this before?

VBA Code:
    Dim rng As Range
    For Each rng In ActiveSheet.UsedRange
        If rng.HasFormula Then
            rng.Formula = rng.Value
        End If
    Next rng

VBA Code:
    Application.DisplayAlerts = False 'stops message box from alerting about pasting over values
    Sheets(reportArray(0)(2)).Cells.Select
    Selection.Copy
    Sheets(reportArray(0)(2)).Range("A1").PasteSpecial Paste:=xlPasteValues
    Application.DisplayAlerts = True 'turns alerts back on

VBA Code:
    With ActiveSheet.UsedRange
        .Value = .Value
    End With
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
That last code should work & the only blanks should be where a cell was blank or had a formula that returned ""
 
Upvote 0
That last code should work & the only blanks should be where a cell was blank or had a formula that returned ""
Hi,

Thanks for the response. This sort of fell off my radar for a while but I am revisiting today. None of those code strings work. If I run the report without trying to get rid of the formulas, I get the following

RowsColumn ColumnColumnColumnColumnColumnColumnColumnColumnColumnColumnColumnColumnColumnColumn
Row$ 4,951$ 9,600$ (4,649)$ 1,067$ 375$ 1,442-3.223.572.4712,7799,630-9,630##########
Row$ 5,187$ -$ 5,187$ -$ 375$ 37513.833.572.4712,7799,630-9,630$ -$ -
Total$ 10,139$ 9,600$ 539$ 1,067$ 750$ 1,8170.307.144.9425,55819,259-19,259

And this is what I get when I try to get ride of the formulas with any of the code listed above
RowsColumnColumnColumnColumnColumnColumnColumnColumnColumnColumnColumnColumnColumnColumnColumn
Row
Row$ 5,187$ -$ 5,187$ -$ 375$ 37513.833.572.4712,7799,630-9,630$ -$ -
Total$-$-$-$-$-$-#DIV/0!------
 
Upvote 0
As I said, the last bit of code you posted should work.
 
Upvote 0

Forum statistics

Threads
1,214,574
Messages
6,120,327
Members
448,956
Latest member
Adamsxl

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