Sub Split_Data()
Range("B3").Select
ActiveCell.CurrentRegion.Select
srcdata = ActiveCell.CurrentRegion.Address
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
srcdata).CreatePivotTable TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Process Name"), "Count of Process Name", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Process Name")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1")
.ColumnGrand = False
.RowGrand = False
End With
ActiveSheet.Name = "Pivot"
Range("B5").Select
Do While ActiveCell.Value <> ""
Selection.ShowDetail = True
ActiveSheet.Name = Range("A2").Value
Sheets("Pivot").Select
ActiveCell.Offset(1, 0).Select
Loop
Application.DisplayAlerts = False
Sheets("Pivot").Delete
Application.DisplayAlerts = True
End Sub
Hi,
Try the below macro
Code:Sub Split_Data() Range("B3").Select ActiveCell.CurrentRegion.Select srcdata = ActiveCell.CurrentRegion.Address ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _ srcdata).CreatePivotTable TableDestination:="", TableName:= _ "PivotTable1", DefaultVersion:=xlPivotTableVersion10 ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1) ActiveSheet.Cells(3, 1).Select ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _ "PivotTable1").PivotFields("Process Name"), "Count of Process Name", xlCount With ActiveSheet.PivotTables("PivotTable1").PivotFields("Process Name") .Orientation = xlRowField .Position = 1 End With With ActiveSheet.PivotTables("PivotTable1") .ColumnGrand = False .RowGrand = False End With ActiveSheet.Name = "Pivot" "Run time error" Application defined-error Range("B5").Select Do While ActiveCell.Value <> "" Selection.ShowDetail = True ActiveSheet.Name = Range("A2").Value Sheets("Pivot").Select ActiveCell.Offset(1, 0).Select Loop Application.DisplayAlerts = False Sheets("Pivot").Delete Application.DisplayAlerts = True End Sub
Sub SaveEach()
Const fDir = "C:\Users\HYMC\theSmallman\Test\"
Dim i As Integer
Dim ar As Variant
Dim rng As Range
Set rng = Range("B3", Range("B" & Rows.Count).End(xlUp))
rng.AdvancedFilter 2, , [H1], True
ar = Range("H2", Range("H" & Rows.Count).End(xlUp))
For i = 1 To UBound(ar)
rng.AutoFilter 1, ar(i, 1)
rng.Resize(, 5).Copy
Workbooks.Add
[B3].PasteSpecial xlPasteAll
Range("B:F").EntireColumn.AutoFit
ActiveWorkbook.SaveAs fDir & ar(i, 1) & ".xlsx"
ActiveWorkbook.Close False
Next i
End Sub
Hi Ramesh
Thanks for providing further clarity. I think this should cover it.
Be sure to get the path right. If you get this right it will work. I have tested this on a valid path.
Code:Sub SaveEach() Const fDir = "C:\Users\HYMC\theSmallman\Test\" Dim i As Integer Dim ar As Variant Dim rng As Range Set rng = Range("B3", Range("B" & Rows.Count).End(xlUp)) rng.AdvancedFilter 2, , [H1], True ar = Range("H2", Range("H" & Rows.Count).End(xlUp)) For i = 1 To UBound(ar) rng.AutoFilter 1, ar(i, 1) rng.Resize(, 5).Copy Workbooks.Add [B3].PasteSpecial xlPasteAll Range("B:F").EntireColumn.AutoFit ActiveWorkbook.SaveAs fDir & ar(i, 1) & ".xlsx" ActiveWorkbook.Close False Next i End Sub
File attached to show workings.
Take care
Smallman