Split Excel
Split Excel
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("emp")
With ws
.Columns(.Columns.Count).Clear
state = rfl.Text
Application.DisplayAlerts = False
ws.Activate
rData.Copy
Windows(state).Activate
ActiveSheet.Paste
ActiveWorkbook.Close SaveChanges:=True
Next rfl
Application.DisplayAlerts = True
End With
ws.Columns(Columns.Count).ClearContents
rData.AutoFilter
End Sub
-----------------------
Topic: Split a master tab into multiple sub tabs with 1 click
Scenario: You want to split the data on a master file into multiple small sub-tabs
by a chosen criteria (eg. Department, Country, etc.)
Function: Macro for Copy sheet, AutoFilter, and Loop
With ActiveWorkbook.Sheets(cell.Value).Range("MasterData")
.AutoFilter Field:=6, Criteria1:="NOT EQUAL TO" & cell.Value,
Operator:=xlFilterValues
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
ActiveSheet.AutoFilter.ShowAllData
Next cell
End Sub
---------------------
Sub copyDatabyCondition()
�copy data if column S isn�t empty
Dim wsSource As Worksheet
Dim wsTarget As Worksheet
�intialization
Set wsSource = ThisWorkbook.Sheets(�INPUT�)
Set wsTarget = ThisWorkbook.Sheets(�Sheet2�)
With wsSource
�for each row in the source table
For gSourceRow = 11 To .[A65536].End(xlUp).Row
�column S isn�t empty?
If .Cells(gSourceRow, �S�) 0 Then
gTargetRow = gTargetRow + 1 �increment row no. & appending a new line
�copying a line from source table to target table
wsTarget.Range(�A� & gTargetRow & �:N� & gTargetRow).Value = _
.Range(�L� & gSourceRow & �:Y� & gSourceRow).Value
End If
Next
End With
End Sub
---------------------
Sub copycolumns()
For i = 2 To lastrow
If Sheet1.Cells(i, 6) = �Maharashtra� Then
Sheet1.Cells(i, 1).Copy
erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Sheet1.Paste Destination:=Worksheets(�Sheet2�).Cells(erow, 1)
Sheet1.Cells(i, 3).Copy
Sheet1.Paste Destination:=Worksheets(�Sheet2�).Cells(erow, 2)
Sheet1.Cells(i, 6).Copy
Sheet1.Paste Destination:=Worksheets(�Sheet2�).Cells(erow, 3)
End If
Next i
Application.CutCopyMode = False
Sheet2.Columns().AutoFit
Range(�A1�).Select
End Sub
--------------
Sub Splitziez()