I am running the following macro to open 130 excel files, and copy them in separate sheets for each entity. It sort of works for what I want to do (although probably not the most efficient). Once a sheet already exists, I want the macro not to create a new sheet again, but skip this step.
I am trying to use the on error code for this, however I can't get the following part to work properly:
On Error Goto skip
Even if the formula below this code has an error, it keeps giving back the notification "subscript out of range".
Does anyone have a clue what I'm doing wrong here?
Sub Macro2()
'Select item Location
Row = 2
nextitem: Row = Row + 1
' Create sheet
Sheets("Location").Select
Week = ActiveSheet.Range("c1").Value
Complete = ActiveSheet.Range("b" & Row).Value
Entity = ActiveSheet.Range("a" & Row).Value
Workbook_Entity = Entity & " - Week " & Week & ".xlsx"
If Complete = "Yes" Then
GoTo nextitem
Else
On Error GoTo Skip
Sheets(Entity).Select
GoTo Skipped2
Exit Sub
Skip:
Sheets.Add(After:=Sheets(Sheets.Count)).Name = Entity
Skipped2:
'Open Workbooks
Workbooks.Open Filename:=ThisWorkbook.Path & "\location\" & Workbook_Entity
Sheets("Week - Hidden").Visible = True
Sheets("Week - Hidden").Select
Columns("A:G").Select
Selection.Copy
Windows("Overview.xlsm").Activate
Sheets(Entity).Select
Range("a1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows(Workbook_Entity).Activate
ActiveWorkbook.Save
Sheets("Week - Hidden").Visible = False
ActiveWindow.Close
'Rotate
If Item_Region = "003" Then
GoTo Enditall
Else
GoTo nextitem
Enditall:
End If
End If
End Sub