• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

COPY 2 SHEETS TO NEW WB WITH TIMESTAMP

I have a macro that copy a sheet of active wb to new wb but only the values and save with timestamp
now i am trying to the new wb to export 2 sheets from the active wb only the values and save with timestamp
the name of sheets are "2018" and "total"

{
Sub Exportminas()
Dim Wb As Workbook
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ActiveWindow.SelectedSheets
If Wb Is Nothing Then
sh.Copy
Set Wb = ActiveSheet.Parent
Else
sh.Copy After:=Wb.Worksheets(Wb.Worksheets.Count)
End If
ActiveSheet.UsedRange.Value = sh.UsedRange.Value
Next
ActiveWorkbook.SaveAs ("C:\newwb " & Format(Now(), "DD-MMM-YYYY hh mm AMPM") & ".xlsx")
End Sub
 
Hi try
Code:
Option Explicit
Sub TwoSheetsAndYourOut()
    Dim nm As Name
    Dim ws As Worksheet
With Application
        .ScreenUpdating = False
        On Error GoTo ErrCatcher
            Sheets(Array("2018", "total")).Copy
        On Error GoTo 0
        For Each ws In ActiveWorkbook.Worksheets
            ws.Cells.Copy
            ws.[A1].PasteSpecial Paste:=xlValues
            ws.Cells.Hyperlinks.Delete
            Application.CutCopyMode = False
        Next ws
        For Each nm In ActiveWorkbook.Names
            nm.Delete
        Next nm
        ActiveWorkbook.SaveAs ("C:\newwb " & Format(Now(), "DD-MMM-YYYY hh mm AMPM") & ".xlsx")
        ActiveWorkbook.Close SaveChanges:=False
      .ScreenUpdating = True
End With
    Exit Sub
ErrCatcher:
    MsgBox "Specified sheets do not exist within this workbook"
End Sub
 
just perfect
one more time you save me from a lot of work.
i was trying some other options by recording some macros but when i use your code worked fine
 
Back
Top