How to copy only a single worksheet to another workbook using vba

后端 未结 4 811
天涯浪人
天涯浪人 2020-12-01 13:11

I have 1 WorkBook(\"SOURCE\") that contains around 20 Sheets.
I want to copy only 1 particular sheet to another Workbook(\"TARGET\") using Exce

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 13:42

    To copy a sheet to a workbook called TARGET:

    Sheets("xyz").Copy After:=Workbooks("TARGET.xlsx").Sheets("abc")
    

    This will put the copied sheet xyz in the TARGET workbook after the sheet abc Obviously if you want to put the sheet in the TARGET workbook before a sheet, replace Before for After in the code.

    To create a workbook called TARGET you would first need to add a new workbook and then save it to define the filename:

    Application.Workbooks.Add (xlWBATWorksheet)
    ActiveWorkbook.SaveAs ("TARGET")
    

    However this may not be ideal for you as it will save the workbook in a default location e.g. My Documents.

    Hopefully this will give you something to go on though.

提交回复
热议问题