Macro: Loop through sheets, copy and paste as values

larinda4

Board Regular
Joined
Nov 15, 2021
Messages
73
Office Version
  1. 365
Platform
  1. Windows
I have this code and I am wanting to loop through all the sheets in my workbook. I want it to unhide all rows/columns, delete all comments and copy/paste the entire sheet as values, then proceed to the next sheet.

VBA Code:
Sub xCheck()

   Dim ws As Worksheet
    
    For Each ws In Worksheets
        ws.Columns.EntireColumn.Hidden = False
        ws.Rows.EntireRow.Hidden = False
        ws.Cells.ClearComments
        ws.Cells.PasteSpecial Paste:=xlPasteValues
        
    Next ws
End Sub

I'm receiving an error for "ws.Cells.PasteSpecial". Any help would be appreciated.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
You have not copied anything before you paste, must be missing: ws.Cells.Copy
 
Upvote 0
Solution
You have not copied anything before you paste
I tried that as well. Here's the code I tried using:

VBA Code:
Sub xCheck()

   Dim ws As Worksheet
    
    For Each ws In Worksheets
        ws.Columns.EntireColumn.Hidden = False
        ws.Rows.EntireRow.Hidden = False
        ws.Cells.ClearComments
        ws.Cells.Select
        ws.Cells.PasteSpecial Paste:=xlPasteValues
        
    Next ws
End Sub

I was also receiving an error for "ws.Cells.Select"
 
Upvote 0
I'm face palming so hard right now. I figured it out.

Here's the code:

VBA Code:
Sub xCheck()

   Dim ws As Worksheet
    
    For Each ws In Worksheets
        ws.Columns.EntireColumn.Hidden = False
        ws.Rows.EntireRow.Hidden = False
        ws.Cells.ClearComments
        ws.Cells.Copy
        ws.Cells.PasteSpecial Paste:=xlPasteValues
        
    Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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