VBA to Select all sheets (except 3), and copy and paste as values

Huples_Cat

New Member
Joined
Jul 28, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a file that generates several worksheets based on a template one (changing certain parameters) and what i need is a macro that selects all those sheets, copies and pastes over them as values so as to hard-code the data, leaving 3 tabs alone.

i have a macro to delete all except those same three sheets so have tried using record macro to get an idea of what i need to amend it with but no luck as of yet.

Here's my delete macro, which includes the three worksheets i also don't want to copy/paste-as-values in the new macro. The s.Delete bit is clearly what i need to relace!

Any ideas anyone?

Dim s

Application.DisplayAlerts = False
For Each s In Sheets
If s.Name <> "Template" And s.Name <> "Input" And _
s.Name <> "Lookup" Then
s.Delete
End If
Next
Application.DisplayAlerts = True
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
try this.

VBA Code:
Sub Do_it()

For Each s In Sheets

If s.Name = "Template" Then GoTo 999
If s.Name = "Input" Then GoTo 999
If s.Name = "Lookup" Then GoTo 999

    s.Cells.Copy
    s.Cells.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

999 Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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