|
当然,这种用代码是最方便的,提供一个我以前写的代码参考一下:
录制筛选的基础上改的,一般了点,但管用。
Sub div()
Dim myrow As Long
Dim mycol As Long
Dim i As Long
myrow = [a65536].End(xlUp).Row
mycol = [iv1].End(xlToLeft).Column
Range("A1:A" & myrow).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Range("A2:A" & myrow).SpecialCells(xlCellTypeVisible).Copy Destination:=Cells(1, mycol + 1)
ActiveSheet.ShowAllData
Range(Cells(1, 1), Cells(1, mycol)).AutoFilter
For i = 1 To Application.CountA(Columns(mycol + 1))
Sheets.Add
ActiveSheet.Name = Cells(i, mycol + 1)
Range(Cells(1, 1), Cells(1, mycol)).AutoFilter Field:=1, Criteria1:=Cells(i, mycol + 1)
Range(Cells(1, 1), Cells(myrow, mycol)).SpecialCells(xlCellTypeVisible).Copy Destination:=ActiveSheet.Range("a1")
Next
Sheets("sheet1").Select
Range(Cells(1, 1), Cells(1, mycol)).AutoFilter
Columns(mycol + 1).ClearContents
End Sub |
|