Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Save Selected Sheets in another workbook

Wondering why I can’t do :

For i = 1 To ThisWorkbook.Sheets.Count
    If ThisWorkbook.Sheets(i).Name <> "DO NOT SAVE" Then ThisWorkbook.Sheets(i).Select Replace:=False
Next i

Selection.Copy

what would be the best way to save all sheets which does not match DO NOT SAVE name in another wb ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try this:

Sub Tester()
    Dim ws As Worksheet, arr(), i As Long
    ReDim arr(0 To ThisWorkbook.Worksheets.Count - 2)
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "DO NOT SAVE" Then
            arr(i) = ws.Name
            i = i + 1
        End If
    Next ws
    Worksheets(arr).Copy
End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading