Replace Formulas with Values (For The Entire Workbook)

hematinsite

New Member
Joined
Nov 3, 2020
Messages
14
Office Version
  1. 2019
Platform
  1. Windows
hi dear
in excel 2019 , Is it possible to have a macro that in my entire workbook in any cell in print area , if i use formula then convert to their value ? i have below vba code and work for small sheets but for big sheets is very heavy and need so time to execute and finish , i want to limit range in print area for convert formula to value in sheets and entire workbook.

Sub FormulasToValues_EntireWorkbook()
'This Macro will replace all formulas from an entire workbook
'with their respective values. It will just changes all
'formulas to values.

WCount = Worksheets.Count
For i = 1 To WCount
If Worksheets(WCount - i + 1).Visible Then
Worksheets(WCount - i + 1).Select
RCount = ActiveCell.SpecialCells(xlLastCell).Row
CCount = ActiveCell.SpecialCells(xlLastCell).Column
For j = 1 To RCount
For k = 1 To CCount
Worksheets(WCount - i + 1).Cells(j, k) = Worksheets(WCount - i + 1).Cells(j, k).Value
Next k
Next j
End If
Next i

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
How about ...
VBA Code:
Sub hematinsite()

    Dim n As Name, r As Range
    For Each n In ThisWorkbook.Names
        If Right(n.Name, 11) = "!Print_Area" Then
            Set r = Range(Replace(n.RefersTo, "=", ""))
            If r.Parent.Visible = xlSheetVisible Then
                r.Copy
                r.PasteSpecial (xlPasteValues)
            End If
        End If
    Next
End Sub
 
Upvote 0
Your code referred to the active workbook, whereas @GWteB 's code refers to the workbook running the macro. If you want the code to refer to the active workbook, replace...

VBA Code:
For Each n In ThisWorkbook.Names

with

VBA Code:
For Each n In ActiveWorkbook.Names

Hope this helps!
 
Upvote 0
Hi what about

Sub test()
WCount = Worksheets.Count
For i = 1 To WCount
If Worksheets(WCount - i + 1).Visible Then
Worksheets(WCount - i + 1).Select
RCount = ActiveCell.SpecialCells(xlLastCell).Row
CCount = ActiveCell.SpecialCells(xlLastCell).Column
a = Cells(1, 1).Resize(RCount, CCount).Value
Cells(1, 1).Resize(RCount, CCount) = a
End If
Next i
End Sub
 
Upvote 0
Solution
Your code referred to the active workbook, whereas @GWteB 's code refers to the workbook running the macro. If you want the code to refer to the active workbook, replace...

VBA Code:
For Each n In ThisWorkbook.Names

with

VBA Code:
For Each n In ActiveWorkbook.Names

Hope this helps!
i did it , but anything to do
 
Upvote 0
Do you in fact have print areas set up using the method Ribbon >> Page Layout tab >> Page Setup group >> Print Area >> Set Print Area?

Can you confirm whether you want the code to work on the active workbook or the workbook running the code?
 
Upvote 0
Maybe it's an issue to do with language. When you look at your Name Manager, are the names for the print areas named Print_Area? If not, how are they named?
 
Upvote 0
@hematinsite, my code assumes that each of your worksheets, as you indicated in your post #1, has a delimited Print_Area, as shown in the accompanying image.
If not then my code has no effect at all.

ScreenShot004.png
 
Upvote 0
Hi what about

Sub test()
WCount = Worksheets.Count
For i = 1 To WCount
If Worksheets(WCount - i + 1).Visible Then
Worksheets(WCount - i + 1).Select
RCount = ActiveCell.SpecialCells(xlLastCell).Row
CCount = ActiveCell.SpecialCells(xlLastCell).Column
a = Cells(1, 1).Resize(RCount, CCount).Value
Cells(1, 1).Resize(RCount, CCount) = a
End If
Next i
End Sub
this work very fast and perfectly . thx dear
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,974
Members
448,934
Latest member
audette89

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