I use this vba to split my excel sheets into multiple files, however, the first sheet into a file usually the original file, and it will be delete.
Right now I am hard coding it with Kill mypath & "\sheet1.xlsx"
Are there anyway to make it dynamic or a string?
can I do something like sht.Name(0) ??? Get the first value of the array?
![]()
Sub Splitbook() mypath = ActiveWorkbook.Path For Each sht In ActiveWorkbook.Sheets sht.Copy ActiveSheet.Cells.Copy ActiveSheet.Cells.PasteSpecial Paste:=xlPasteValues ActiveSheet.Cells.PasteSpecial Paste:=xlPasteFormats ActiveWorkbook.SaveAs _ Filename:=mypath & "\" & sht.Name & ".xlsx" ActiveWorkbook.Close savechanges:=False Next sht Kill mypath & "\sheet1.xlsx" End Sub
Bookmarks