Ok.Check @ eveIts kinda urgent. But understand your situation.
Option Explicit
Sub Split_Multiple_Sheets_in_A_Workbook_v2()
Dim ws As Worksheet, MyRange As Range, i As Long, N As Workbook
Dim UList As Collection, UListValue As Variant, myPath As String, myFileName As String
Dim col_filter As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Either this...
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'col_filter = Application.InputBox("Which Col to filter")
'If Not col_filter <> False Then Exit Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'or
col_filter = 2
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
myPath = Application.ThisWorkbook.Path & "\"
'--------------------------------------------------------------------------
'Make a carbon copy of the workbook
myFileName = Format(Now, "d_m_yyyy_h_m_s") & "_" & Application.ThisWorkbook.Name
'ThisWorkbook.SaveCopyAs myPath & myFileName
'--------------------------------------------------------------------------
'From where to find filter criteria
Set MyRange = Sheets("App Level").UsedRange
'------------------------------------------------------------------------
'Make a collection of unique value of APP ID
Set UList = New Collection
On Error Resume Next
For i = 2 To MyRange.Rows.Count
UList.Add MyRange.Cells(i, col_filter), CStr(MyRange.Cells(i, col_filter))
Next
On Error GoTo 0
'------------------------------------------------------------------------
'========================================================================
'Strat loop with unique collection
For Each UListValue In UList
Set N = Workbooks.Add(xlWBATWorksheet)
For Each ws In ThisWorkbook.Sheets
If Not InStr(1, "OverviewReferences", ws.Name) > 0 Then
ws.UsedRange.AutoFilter col_filter, UListValue
With N
ws.AutoFilter.Range.Copy
.Sheets.Add().Name = ws.Name
.Sheets(ws.Name).Paste
ActiveSheet.Cells.EntireColumn.AutoFit
End With
ws.AutoFilterMode = False
End If
Next
'========================================================================
ThisWorkbook.Sheets("References").Copy Before:=N.Sheets(1)
ThisWorkbook.Sheets("Overview").Copy Before:=N.Sheets(1)
'========================================================================
'Delete Empty Sheets
For Each ws In N.Sheets
If Not InStr(1, "OverviewReferences", ws.Name) > 0 Then
If IsEmpty(ws.UsedRange) Then ws.Delete
End If
Next
'========================================================================
'=================================================================================
'Save the created workbook
N.SaveAs myPath & AlphaNumericOnly(UListValue.Value)
N.Close False
'=================================================================================
Next
MsgBox "DONE-DONE-DONE", vbInformation
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Option Explicit
Sub Split_Multiple_Sheets_in_A_Workbook_v2()
Dim ws As Worksheet, MyRange As Range, i As Long, N As Workbook
Dim UList As Collection, UListValue As Variant, myPath As String, myFileName As String
Dim col_filter As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Either this...
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'col_filter = Application.InputBox("Which Col to filter")
'If Not col_filter <> False Then Exit Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'or
col_filter = 2
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
myPath = Application.ThisWorkbook.Path & "\"
'--------------------------------------------------------------------------
'Make a carbon copy of the workbook
myFileName = Format(Now, "d_m_yyyy_h_m_s") & "_" & Application.ThisWorkbook.Name
'ThisWorkbook.SaveCopyAs myPath & myFileName
'--------------------------------------------------------------------------
'From where to find filter criteria
Set MyRange = Sheets("App Level").UsedRange
'------------------------------------------------------------------------
'Make a collection of unique value of APP ID
Set UList = New Collection
On Error Resume Next
For i = 2 To MyRange.Rows.Count
UList.Add MyRange.Cells(i, col_filter), CStr(MyRange.Cells(i, col_filter))
Next
On Error GoTo 0
'------------------------------------------------------------------------
'========================================================================
'Strat loop with unique collection
For Each UListValue In UList
Set N = Workbooks.Add(xlWBATWorksheet)
For Each ws In ThisWorkbook.Sheets
If Not InStr(1, "OverviewReferences", ws.Name) > 0 Then
ws.UsedRange.AutoFilter col_filter, UListValue
With N
ws.AutoFilter.Range.Copy
.Sheets.Add().Name = ws.Name
.Sheets(ws.Name).Paste
ActiveSheet.Cells.EntireColumn.AutoFit
End With
ws.AutoFilterMode = False
End If
Next
'========================================================================
ThisWorkbook.Sheets("References").Copy Before:=N.Sheets(1)
ThisWorkbook.Sheets("Overview").Copy Before:=N.Sheets(1)
'========================================================================
'Delete Empty Sheets
For Each ws In N.Sheets
If Not InStr(1, "OverviewReferences", ws.Name) > 0 Then
If IsEmpty(ws.UsedRange) Then ws.Delete
End If
Next
'========================================================================
'=================================================================================
'Save the created workbook
N.SaveAs myPath & AlphaNumericOnly(UListValue.Value)
N.Close False
'=================================================================================
Next
MsgBox "DONE-DONE-DONE", vbInformation
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
' this will exclude non AlphaNumericOnly from a string
Function AlphaNumericOnly(strSource As String) As String
Dim i As Integer
Dim strResult As String
For i = 1 To Len(strSource)
Select Case Asc(Mid(strSource, i, 1))
Case 32, 48 To 57, 65 To 90, 97 To 122: 'include 32 if space needs to include
strResult = strResult + Mid(strSource, i, 1)
End Select
Next
AlphaNumericOnly = strResult
End Function
Quick : My Column filter is on D4. Hence, it doesnt let the code go ahead
You haven't said the same earlier.What i meant was that we have a line of code stating :
col_filter = 4
It take D1 as the filter to cut the data.... but the column header is on D4. Hence, the col_filter should consider D4 and not just column 4.
The code goes to DONE DONE DONE without doing anything
Yes, understand that it takes column 2. i have changed in to column 4 but still it goes to DONE DONE DONE without splitting the workbooks
I am unable to send the sample workbook as its against my company's legal policies. I will try and do something from home and upload.