|
Sub 宏1()
Dim sht As Worksheet
Application.ScreenUpdating = False
Set sht = Sheets.Add(After:=Sheets(Sheets.Count))
Sheets("5月考勤").Columns("P:P").Copy sht.Columns("A:A")
ActiveSheet.Range("$A$1:$A$" & sht.Range("a65320").End(xlUp).Row).RemoveDuplicates Columns:=1, Header:=xlNo
arr = sht.UsedRange
For i = 2 To UBound(arr)
Set sht = Sheets.Add(After:=Sheets(Sheets.Count))
sht.Name = arr(i, 1)
With sht.ListObjects.Add(SourceType:=0, Source:="ODBC;DSN=Excel Files;DBQ=" & ThisWorkbook.FullName, Destination:=Range( _
"$A$1")).QueryTable
.CommandText = "SELECT * FROM [5月考勤$] where [部门]='" & arr(i, 1) & "'"
.ListObject.DisplayName = "表_" & i
.Refresh BackgroundQuery:=False
End With
sht.Cells.EntireColumn.AutoFit
Next i
Application.ScreenUpdating = True
End Sub
|
|