Hi!
I have a code that splits a workbook into multiple workbooks based on unique values in the first column found in Sheet1, however I just want it to also pull the second sheet (Sheet2) that is within the original workbook into all of the workbooks that split.
Any help would be greatly appreciated, the code can be found below. Thank you! :
Sub CreateWorkbooks()
Application.ScreenUpdating = False
Dim LastRow As Long, super As Range, RngList As Object, item As Variant, srcWB As Workbook, srcWS As Worksheet
Set srcWB = ThisWorkbook
Set srcWS = srcWB.Sheets("Sheet1")
LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set RngList = CreateObject("Scripting.Dictionary")
With srcWS
For Each Rng In .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
If Not RngList.Exists(Rng.Value) Then
RngList.Add Rng.Value, Nothing
End If
Next
End With
For Each item In RngList
srcWS.Copy
With Cells(1).CurrentRegion
.AutoFilter 1, "<>" & item
ActiveSheet.AutoFilter.Range.Offset(1, 0).EntireRow.Delete
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
ActiveWorkbook.SaveAs Filename:=srcWB.Path & Application.PathSeparator & item & ".xlsx", FileFormat:=51
ActiveWorkbook.Close False
End With
Next item
Application.ScreenUpdating = True
End Sub
I have a code that splits a workbook into multiple workbooks based on unique values in the first column found in Sheet1, however I just want it to also pull the second sheet (Sheet2) that is within the original workbook into all of the workbooks that split.
Any help would be greatly appreciated, the code can be found below. Thank you! :
Sub CreateWorkbooks()
Application.ScreenUpdating = False
Dim LastRow As Long, super As Range, RngList As Object, item As Variant, srcWB As Workbook, srcWS As Worksheet
Set srcWB = ThisWorkbook
Set srcWS = srcWB.Sheets("Sheet1")
LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set RngList = CreateObject("Scripting.Dictionary")
With srcWS
For Each Rng In .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
If Not RngList.Exists(Rng.Value) Then
RngList.Add Rng.Value, Nothing
End If
Next
End With
For Each item In RngList
srcWS.Copy
With Cells(1).CurrentRegion
.AutoFilter 1, "<>" & item
ActiveSheet.AutoFilter.Range.Offset(1, 0).EntireRow.Delete
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
ActiveWorkbook.SaveAs Filename:=srcWB.Path & Application.PathSeparator & item & ".xlsx", FileFormat:=51
ActiveWorkbook.Close False
End With
Next item
Application.ScreenUpdating = True
End Sub