|
- Sub test()
- '功能: 把部分拆分到各对应名称工作表,没有则新建。新纪录会追加到结尾,但不会检测重名记录!
- '部门需放到第三列,部门无需排序。 所以运行效率会差些。可追加进度条改善交互。
- '没有编写表头标题行,选工作组粘贴一下吧。
- Dim arr() As Variant
- Dim lngMaxRow As Long
- Dim lngMaxCol As Long
- Worksheets("Sheet1").Activate
- lngMaxRow = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
- lngMaxCol = Cells(1, ActiveSheet.Columns.Count).End(xlToLeft).Column
- arr = Range(Cells(2, 1), Cells(lngMaxRow, lngMaxCol)).Value
- Dim i As Long, j As Long
- Dim shtWorksheet As Worksheet
- Dim blnFind As Boolean
- blnFind = False
- For i = 1 To UBound(arr, 1)
- For Each shtWorksheet In Worksheets
- If shtWorksheet.Name = arr(i, 3) Then blnFind = True: Exit For
- Next shtWorksheet
- If blnFind = True Then
- shtWorksheet.Activate
- lngMaxRow = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
- For j = 1 To UBound(arr, 2)
- Cells(lngMaxRow + 1, j) = arr(i, j)
- Next j
- Else
- Worksheets.Add after:=Worksheets(Sheets.Count)
- ActiveSheet.Name = arr(i, 3)
- lngMaxRow = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
- For j = 1 To UBound(arr, 2)
- Cells(lngMaxRow + 1, j) = arr(i, j)
- Next j
- End If
- blnFind = False
- Next i
- End Sub
复制代码 |
|