Hello all,
I have an Excel workbook with up to 100 sheets.
With VBA, I just want loop through all the tabs, and copy worksheets to other files with the same name as all the sheets.
For example, a sheet name could be "123456789 P&L", and I just want to copy that to an exisiting file named 123456789.xlsx, as a new sheet tab.
I have taken multiple shots at this, to no avail. Below is non-successful code. Any feedback would be most appreciated. An accountant by trade, and I'm at my VBA ceiling right now. Thanks in advance.
Sub CopySheets9()
Dim wbTO As Workbook, wbFrom As Workbook
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim FileName As String
Set wbFrom = ThisWorkbook
Application.DisplayAlerts = False
With wbFrom
j = .Worksheets.Count
For k = 1 To j
If wbFrom.Worksheets(k).Name Like "500*" Then
Set FileName = Left(wbFrom.Worksheets(k).Name, 9)
Set wbTO = Worbooks.Open("E:\TPL VBA Project\" & "FileName" & ."xlsx")
wbFrom.Sheets(k).Copy After:=wbTO.Sheets("Sheet1")
wbTO.SaveAs ("E:\TPL VBA Project\wbTO")
End If
Next
End With
Application.DisplayAlerts = True
End Sub
I have an Excel workbook with up to 100 sheets.
With VBA, I just want loop through all the tabs, and copy worksheets to other files with the same name as all the sheets.
For example, a sheet name could be "123456789 P&L", and I just want to copy that to an exisiting file named 123456789.xlsx, as a new sheet tab.
I have taken multiple shots at this, to no avail. Below is non-successful code. Any feedback would be most appreciated. An accountant by trade, and I'm at my VBA ceiling right now. Thanks in advance.
Sub CopySheets9()
Dim wbTO As Workbook, wbFrom As Workbook
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim FileName As String
Set wbFrom = ThisWorkbook
Application.DisplayAlerts = False
With wbFrom
j = .Worksheets.Count
For k = 1 To j
If wbFrom.Worksheets(k).Name Like "500*" Then
Set FileName = Left(wbFrom.Worksheets(k).Name, 9)
Set wbTO = Worbooks.Open("E:\TPL VBA Project\" & "FileName" & ."xlsx")
wbFrom.Sheets(k).Copy After:=wbTO.Sheets("Sheet1")
wbTO.SaveAs ("E:\TPL VBA Project\wbTO")
End If
Next
End With
Application.DisplayAlerts = True
End Sub