Hi Team,
I have one input file, which contain list of city,every city has Data in it.
Task is split the data, Copy each sheet Data to a new workbook and
save new workbook with first two letters of Citi name.
if citi names of first two letter has come multiple times add all those sheets to single workbook.
Below is attempted code which works, but is there any alternate way to speed up the macro.
I have total 60 sheets in input file have to seperate it,
Output Generated 30 new workbook will generated, 30 sheets clubbed in same workbook where sheetnames matches with first two letter.
Time takes around 40 mins, Can we speed up the macro.
Option Explicit
Thanks
mg
I have one input file, which contain list of city,every city has Data in it.
Task is split the data, Copy each sheet Data to a new workbook and
save new workbook with first two letters of Citi name.
if citi names of first two letter has come multiple times add all those sheets to single workbook.
Below is attempted code which works, but is there any alternate way to speed up the macro.
I have total 60 sheets in input file have to seperate it,
Output Generated 30 new workbook will generated, 30 sheets clubbed in same workbook where sheetnames matches with first two letter.
Time takes around 40 mins, Can we speed up the macro.
Option Explicit
VBA Code:
Sub Seperate_Data_asperCiti()
Dim wbk_s As Workbook
Dim dest_wbk As Workbook
Dim sht As Worksheet
Dim i As Long
Dim arr_citi As Variant
Application.DisplayAlerts = False
Application.ScreenUpdating = False
arr_citi = Array("IN", "MU", "PU", "BA", "HD", "GO", "HM", "AD", "TA", "SO", "KO", "Lo") List is lenghty
For i = LBound(arr_citi) To UBound(arr_citi) ' Find sheetName as per city
Set wbk_s = Workbooks.Open("D:\Input_File\Look_up.xlsx")
For Each sht In wbk_s.Sheets
If Left(sht.Name, 2) = arr_citi(i) Then
If Dir(Path & "\" & arr_citi(i) & ".xlsx") = "" Then
sht.Copy
Application.ActiveWorkbook.SaveAs Filename = Path & "\" & arr_citi(i) & ".xlsx"
Application.ActiveWorkbook.Close False
Else
Set dest_wbk = Workbooks.Open(Path & "\" & arr_citi(i) & ".xlsx", False, False)
sht.Copy after:=dest_wbk.Sheets(dest_wbk.Worksheets.Count)
dest_wbk.Save
dest_wbk.Close True
End If
End If
Next
Next i
wbk_s.Close True
MsgBox "Data seperated as per Citi"
Application.DisplayAlerts = true
Application.ScreenUpdating = true
End Sub
Thanks
mg