Convert entire workbook to values

Kaps_mr2

Well-known Member
Joined
Jul 5, 2008
Messages
1,589
Office Version
  1. 365
Platform
  1. Windows
I am trying to find the most efficient way of converting an entire workbook to values. I did find the following code from another site :-

However I get an error on the line in bold. Can anybody tell me why ? Thanks

Regards

Kaps

Rich (BB code):
Public nirvana_workbook as workbook
 
Public sub convert_to_values()
nirvana_workbook.activate
 
 Worksheets.Select
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    ActiveSheet.Select
    Application.CutCopyMode = False
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Maybe it's my screen, but I can't see a bold line.

Where is nirvana_workbook set up?

Shouldn't you be looping through the sheets of the workbook ... your current logic doesn't look like it would work even if you got the syntax right?
Code:
For Each ws in nirvana_workbook.WorkSheets
     ws.UsedRange.Values = ws.UsedRange.Values 
Next
 
Upvote 0
Hi Glenn,

Thanks - I got this from another site - it seemed to try to work by selecting the entire workbook in one go. Your approach does make sense - much appreciated.

kind regards

Kaps
 
Upvote 0
Your code works fine for me. I wasn't aware you could do all the sheets at once but it does work. Learn something every day! I can't see why it doesn't like selecting the worksheets. I presume you've tried stepping through the code. What error is it giving you?
 
Upvote 0
Actually Glenn I get object does not support this property or method on the second line of your code:-


For Each ws in nirvana_workbook.WorkSheets ws.UsedRange.Values = ws.UsedRange.Values Next</pre>
gsbelbin I can't remember the exact error I got but it was along the same lines. Unfortunately my macro takes an age to run (lots of large data files).

Thinking I probably need to combine the two approaches:-

Code:
For Each ws in nirvana_workbook.WorkSheets
ws.cells.select
selection.copy
selection.pastespecial paste:=xlpastevalues
ws.select
application.cutcopymode = false
next

</pre>

One of my worksheets has 150k rows in it - so I am looking for a fast solution. thanks

Kaps
 
Upvote 0
Typo,

ws.UsedRange.Values

should be:

ws.UsedRange.Value
 
Upvote 0
Hi Glenn,

I now get a fatal "Out of memmory error" - any other thoughts ? Thanks

Regards

Kaps
 
Upvote 0
And do you know how far through the processing it gets before that error occurs? Have you tried printing out the UsedRange address at very loop, to see if it's a particular range size that causes the problem?
 
Upvote 0
Hi Glenn,

The largest worksheet "Tech Detail" has 171,000 rows on it - and this one causes the error.

I don't actually need this worksheet. I did try and do all the other worksheets as values and delete "Tech Detail" at the end but got REF# errors everywhere. Any thoughts ? Thanks

Regards

Kaps
 
Upvote 0
Hi Kaps,

I don't actually need this worksheet. I did try and do all the other worksheets as values and delete "Tech Detail" at the end but got REF# errors everywhere. Any thoughts ? Thanks
How can #REF! errors appear in cells that have already been converted to values? That is not possible.
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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