Hello everyone
I am in process of creating a code to copy the data from 11 tabs of the same file - paste it in a tab of the same file and then create 11 different files so they are sent to diferent owners.
I have tested the 1st tab and when I continue to the next one to make sure that the code works it actualy doesnt. The first file is created but the macro gets stuck with no error and does not continue to the followin tab. The macro gets stuck where I have it in red bold letters. I have added many notes into it as I have to hand it over to someone else for maintenance, so if you could please alter it as less as possible.
Thanks a lot
F
I am in process of creating a code to copy the data from 11 tabs of the same file - paste it in a tab of the same file and then create 11 different files so they are sent to diferent owners.
I have tested the 1st tab and when I continue to the next one to make sure that the code works it actualy doesnt. The first file is created but the macro gets stuck with no error and does not continue to the followin tab. The macro gets stuck where I have it in red bold letters. I have added many notes into it as I have to hand it over to someone else for maintenance, so if you could please alter it as less as possible.
Thanks a lot
F
Code:
'declarations for naming the file, declaring the path, file name to open master workbook, xWB to close and ws to unhide th sheets
Dim path As String
Dim filename As String
Dim MyFile As String
Dim xWB As Workbook
'Dim ws As Worksheet
'looking for hidden sheets and unhide them
For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
'çopy and paste from the individual tabs to the pivot database
Sheets("1.P064001").Select
Columns("A:u").Select
Selection.Copy
Sheets("database").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'copy the file name from the individual tab to the pivot database
Sheets("1.P064001").Select
Range("X1").Select
Selection.Copy
Sheets("database").Select
Range("AC1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'ActiveWindow.SelectedSheets.Visible = False
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.RefreshAll
'save workbook
Sheets("Country By Account").Select
filename = Sheets("database").Range("AC1")
path = Sheets("database").Range("xfd1")
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs filename:=path & filename & ".xlsx", FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = True
', FileFormat:=ThisWorkbook.FileFormat this is the file format if we want the workbook to be xlsm
'The below code does not allow warning to pop up.
Application.EnableEvents = True
Sheets(Array("ALL", "1.P064001", "2.SR Total")).Select
Application.DisplayAlerts = False
'delete selected sheets.
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Sheets("Country By Account").Select
ActiveWorkbook.Save
MyFile = Sheets("instructions").Range("d5")
Workbooks.Open filename:=MyFile
Application.ScreenUpdating = False
'closing the not active workbooks
For Each xWB In Application.Workbooks
If Not (xWB Is Application.ActiveWorkbook) Then
xWB.Close
End If
Next
[U][I][B][COLOR=#FF0000] Sheets("2.SR Total").Select
Columns("A:U").Select
Selection.Copy[/COLOR][/B][/I][/U]
Last edited by a moderator: