Kmahraz
Member
Hello,
I have a large data set , this data is all contained in a single worksheet. I wish excel to separate the data according to column "A"then place each value in a separate worksheet in the same workbook and named the same as the name in column A.
I found this code and would like to see if someone can help me fix and make it work to meet my needs.
Regards,
K
I have a large data set , this data is all contained in a single worksheet. I wish excel to separate the data according to column "A"then place each value in a separate worksheet in the same workbook and named the same as the name in column A.
I found this code and would like to see if someone can help me fix and make it work to meet my needs.
Regards,
K
Code:
Sub SplitData()Dim DataMarkers(), Names As Range, name As Range, n AsLong, i AsLong
Set Names = Range("A2:A"& Range("A1").End(xlDown).Row)
n =0
DeleteWorksheets
ForEach name In NamesIf name.Offset(1,0)<> name ThenReDimPreserve DataMarkers(n)
DataMarkers(n)= name.Row
Worksheets.Add(After:=Worksheets(Worksheets.Count)).name = name
n = n +1EndIfNext name
For i =0To UBound(DataMarkers)If i =0Then
Worksheets(1).Range("A2:C"& DataMarkers(i)).Copy Destination:=Worksheets(i +2).Range("A1")Else
Worksheets(1).Range("A"&(DataMarkers(i -1)+1)&":C"& DataMarkers(i)).Copy Destination:=Worksheets(i +2).Range("A1")EndIfNext i
EndSub
Sub DeleteWorksheets()Dim ws As Worksheet, activeShtIndex AsLong, i AsLong
activeShtIndex = ActiveSheet.Index
Application.DisplayAlerts =FalseFor i = ThisWorkbook.Worksheets.Count To1Step-1If i <> activeShtIndex Then
Worksheets(i).Delete
EndIfNext i
Application.DisplayAlerts =TrueEndSub
