sachin482
02-02-2018, 05:45 PM
i have a macro as below of splitting multiple sheets but after splitting the formatting gets changed and freeze column also not reflecting i want to keep formatting ,header,aliment and freezing as the main sheet can it is possible
The same has been posted in other forum as link below
https://www.mrexcel.com/forum/excel-questions/1041465-multiple-sheet-splitting.html
Sub test()
Dim ws As Worksheet, a, e, i As Long, ii As Long, w, wb As Workbook
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For Each ws In Worksheets
a = Intersect(ws.Rows("3:" & Rows.Count), _
ws.Range("a3").CurrentRegion).Value
ReDim w(1 To UBound(a, 2))
For i = 2 To UBound(a, 1)
If Not .exists(a(i, 1)) Then
Set .Item(a(i, 1)) = CreateObject("Scripting.Dictionary")
End If
If Not .Item(a(i, 1)).exists(ws.Name) Then
Set .Item(a(i, 1))(ws.Name) = _
CreateObject("System.Collections.ArrayList")
For ii = 1 To UBound(a, 2)
w(ii) = a(1, ii)
Next
.Item(a(i, 1))(ws.Name).Add w
End If
For ii = 1 To UBound(a, 2)
w(ii) = a(i, ii)
Next
.Item(a(i, 1))(ws.Name).Add w
Next
Next
For Each e In .keys
Set wb = Workbooks.Add
For i = 0 To .Item(e).Count - 1
If i + 1 > wb.Sheets.Count Then
wb.Sheets.Add after:=wb.Sheets(wb.Sheets.Count)
wb.Sheets(wb.Sheets.Count).Name = .Item(e).keys()(i)
Else
wb.Sheets(i + 1).Name = .Item(e).keys()(i)
End If
w = Application.Index(.Item(e).items()(i).ToArray, 0, 0)
wb.Sheets(.Item(e).keys()(i)).Cells(1) _
.Resize(UBound(w, 1), UBound(w, 2)).Value = w
Next
wb.SaveAs ThisWorkbook.Path & "\" & e & ".xlsx"
wb.Close
Next
End With
End Sub
The same has been posted in other forum as link below
https://www.mrexcel.com/forum/excel-questions/1041465-multiple-sheet-splitting.html
Sub test()
Dim ws As Worksheet, a, e, i As Long, ii As Long, w, wb As Workbook
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For Each ws In Worksheets
a = Intersect(ws.Rows("3:" & Rows.Count), _
ws.Range("a3").CurrentRegion).Value
ReDim w(1 To UBound(a, 2))
For i = 2 To UBound(a, 1)
If Not .exists(a(i, 1)) Then
Set .Item(a(i, 1)) = CreateObject("Scripting.Dictionary")
End If
If Not .Item(a(i, 1)).exists(ws.Name) Then
Set .Item(a(i, 1))(ws.Name) = _
CreateObject("System.Collections.ArrayList")
For ii = 1 To UBound(a, 2)
w(ii) = a(1, ii)
Next
.Item(a(i, 1))(ws.Name).Add w
End If
For ii = 1 To UBound(a, 2)
w(ii) = a(i, ii)
Next
.Item(a(i, 1))(ws.Name).Add w
Next
Next
For Each e In .keys
Set wb = Workbooks.Add
For i = 0 To .Item(e).Count - 1
If i + 1 > wb.Sheets.Count Then
wb.Sheets.Add after:=wb.Sheets(wb.Sheets.Count)
wb.Sheets(wb.Sheets.Count).Name = .Item(e).keys()(i)
Else
wb.Sheets(i + 1).Name = .Item(e).keys()(i)
End If
w = Application.Index(.Item(e).items()(i).ToArray, 0, 0)
wb.Sheets(.Item(e).keys()(i)).Cells(1) _
.Resize(UBound(w, 1), UBound(w, 2)).Value = w
Next
wb.SaveAs ThisWorkbook.Path & "\" & e & ".xlsx"
wb.Close
Next
End With
End Sub