Maco to copy and paste data on all sheets as values

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have the following code below to copy and paste data as vaklues onm all sheetd

Code:
 Sub convertAllSheetstoValues()

    For Each ws In ThisWorkbook.Worksheets
        ws.UsedRange.Value = ws.UsedRange.Value
    Next
    
End Sub

However, when running the code, I get a run time error "Application-defined or object defined error"

The code below is highlighted


Code:
 ws.UsedRange.Value = ws.UsedRange.Value

It would be appreciated if someone could kindly amend my code
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I tested your macro and it worked properly.
 
Upvote 0
Do you have any protected cells on any of your sheets?
 
Upvote 0
I tested your macro and it worked properly.
Mumps, I am not sure what may causing this. I run a macro to unprotect all cells and then run this macro and got a run time error
 
Upvote 0
Please use code tags and post the code you are using.
 
Upvote 0
Do you have any errors (or formulas that return errors) in any of your cells?
That could be causing issues also.

This should at least let you know which sheet is causing issues:
VBA Code:
Sub convertAllSheetstoValues()

    Dim ws As Worksheet
    
    On Error GoTo err_check
    For Each ws In ThisWorkbook.Worksheets
        ws.UsedRange.Value = ws.UsedRange.Value
    Next ws
    On Error GoTo 0
    
    Exit Sub
    
err_check:
    MsgBox "Error with sheet " & ws.Name
    
End Sub
 
Upvote 0
Solution
Thanks Joe. There were hidden columns that was cauing the issue on some of the sheets
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,214,570
Messages
6,120,297
Members
448,954
Latest member
EmmeEnne1979

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