Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

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("Master sheet")       
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
1 If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol),
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(xlCellT
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

Note: In the above code:

 vcol =1 , the number 1 is the column number that you want to split the data
based on.
 Set ws = Sheets("Master sheet"), Master sheet is the sheet name that you
want to apply this code.
 title = "A1:C1" , A1:C1 is the range of the title.
 For multiple range change
 Dim vcol, i As Integer to Dim vcol As Long, i As Long
Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ThisWorkbook.Sheets
    xWs.Copy
    Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name &
".xlsx"
    Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

REMOVE ZERO MACRO


Sub DeleteZeroRow()
'Updateby20140616
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address,
Type:=8)
Application.ScreenUpdating = False
Do
    Set Rng = WorkRng.Find("0", LookIn:=xlValues)
    If Not Rng Is Nothing Then
        Rng.EntireRow.Delete
    End If
Loop While Not Rng Is Nothing
Application.ScreenUpdating = True
End Sub
OR

Sub DeleteRowIfContainZero()

Set myRange = Application.Selection

Set myRange = Application.InputBox("Select one Range that you want to delete row if it contains
zero:", "DeleteRowIfContainZero", myRange.Address, Type:=8)

Do

Set myCell = myRange.Find("0", LookIn:=xlValues)

If Not myCell Is Nothing Then

myCell.EntireRow.Delete

End If

Loop While Not myCell Is Nothing

End Sub

PRESS F5 WHEN ASK FOR RANGE SELECT THE COLUMN FOR REMOVAL OF ZERO

You might also like