Last active
February 11, 2018 09:03
-
-
Save scq000/6c64fe8469e4f0d8f0d71b234016ebd8 to your computer and use it in GitHub Desktop.
SplitExcel.xlsb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub SplitData() | |
'Updateby20140617 | |
Dim WorkRng As Range | |
Dim xRow As Range | |
Dim SplitRow As Integer | |
Dim xWs As Worksheet | |
On Error Resume Next | |
xTitleId = "KutoolsforExcel" | |
Set WorkRng = Application.Selection | |
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) | |
SplitRow = Application.InputBox("Split Row Num", xTitleId, 5, Type:=1) | |
Set xWs = WorkRng.Parent | |
Set xRow = WorkRng.Rows(1) | |
Application.ScreenUpdating = False | |
For i = 1 To WorkRng.Rows.Count Step SplitRow | |
resizeCount = SplitRow | |
If (WorkRng.Rows.Count - xRow.Row + 1) < SplitRow Then resizeCount = WorkRng.Rows.Count - xRow.Row + 1 | |
xRow.Resize(resizeCount).Copy | |
Application.Worksheets.Add after:=Application.Worksheets(Application.Worksheets.Count) | |
Application.ActiveSheet.Range("A1").PasteSpecial | |
Set xRow = xRow.Offset(SplitRow) | |
Next | |
Application.CutCopyMode = False | |
Application.ScreenUpdating = True | |
End Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub parse_data() | |
Dim lr As Long | |
Dim ws As Worksheet | |
Dim vcol, i As Integer | |
Dim icol As Long | |
Dim myarr As Variant | |
Dim title As String | |
Dim titlerow As Integer | |
vcol = 1 | |
Set ws = Sheets("Sheet1") | |
lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row | |
title = "A1:C1" | |
titlerow = ws.Range(title).Cells(1).Row | |
icol = ws.Columns.Count | |
ws.Cells(1, icol) = "Unique" | |
For i = 2 To lr | |
On Error Resume Next | |
If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then | |
ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol) | |
End If | |
Next | |
myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants)) | |
ws.Columns(icol).Clear | |
For i = 2 To UBound(myarr) | |
ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & "" | |
If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then | |
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & "" | |
Else | |
Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count) | |
End If | |
ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1") | |
Sheets(myarr(i) & "").Columns.AutoFit | |
Next | |
ws.AutoFilterMode = False | |
ws.Activate | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment