Vba macro does not continue to next

ffanias

New Member
Joined
Dec 27, 2017
Messages
5
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

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:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
How does it get 'stuck'?

Are you getting errors?
 
Upvote 0
No errors......at all. the last step of the macro is to close all the workbooks that were open, exept the active one. That is functioning well, the active workbook remains open and the rest are closed and saved. So I want the macro to continue in the active workbook, - go to Sheet 2.SR TOtal, copy from Column A to U, go to the declared page, paste and continue....... But there is no error.

Thank you for your time
 
Upvote 0
Are you trying to create 11 new workbooks from 11 tabs in the existing workbook?
 
Upvote 0
Hello Norie,
Thanks again. I have figured it out. The macro had a "save as " code and so the macro was stopping at that point.
Thanks for your time
 
Upvote 0

Forum statistics

Threads
1,223,970
Messages
6,175,710
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top