|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
练习拆表
- Sub CreateTable()
- Dim aData, aTemp, i As Long
- Dim dMonth As Object
- Set dMonth = CreateObject("scripting.dictionary")
-
- If Sheets("数据").FilterMode Then Sheets("数据").ShowAllData
- aData = Range("a1").CurrentRegion
- For i = 1 To UBound(aData, 2)
- If aData(2, i) Like "*月" Then
- dMonth(aData(2, i)) = i
- End If
- Next
-
- Dim strKey As String, index As Long
- Dim aClassMonth, s As Long
- Dim dClass As Object
- Set dClass = CreateObject("scripting.dictionary")
- For i = 3 To UBound(aData) - 1
- For s = 0 To dMonth.Count - 1
- strKey = aData(i, 3) & "/" & dMonth.keys()(s)
- If Not dClass.exists(strKey) Then
- aClassMonth = Sheets("确认签字").Range("a1").CurrentRegion
- aClassMonth(1, 1) = VBA.Replace(aClassMonth(1, 1), "月", dMonth.keys()(s))
- aClassMonth(2, 1) = 3
- dClass(strKey) = aClassMonth
- End If
- aTemp = dClass(strKey)
- aTemp(2, 1) = aTemp(2, 1) + 1
- index = aTemp(2, 1)
- If index <= 36 Then
- aTemp(index, 2) = aData(i, 2)
- aTemp(index, 3) = aData(i, 3)
- aTemp(index, 4) = aData(i, dMonth.items()(s))
- Else
- index = index - 36 + 3
- aTemp(index, 8) = aData(i, 2)
- aTemp(index, 9) = aData(i, 3)
- aTemp(index, 10) = aData(i, dMonth.items()(s))
- End If
- dClass(strKey) = aTemp
- Next
- Next
-
- With Application
- .ScreenUpdating = False
- .DisplayAlerts = False
- .AskToUpdateLinks = False
- .Calculation = xlCalculationManual
- End With
-
- Dim strMonth As String, p As Long
- On Error Resume Next
- For i = 0 To dMonth.Count - 1
- strMonth = dMonth.keys()(i)
- Sheets.Add(after:=Sheets(Sheets.Count)).Name = strMonth
- If Err.Number Then
- ActiveSheet.Delete
- Err.Clear
- End If
- p = 0
- For s = 0 To dClass.Count - 1
- strKey = dClass.keys()(s)
- If InStr(strKey, strMonth) Then
- index = 1 + 37 * p
- With Sheets(strMonth)
- Sheets("确认签字").Range("a1").CurrentRegion.Copy
- .Range("a" & index).PasteSpecial Paste:=xlPasteFormats
- .Range("a" & index).Resize(UBound(aTemp), UBound(aTemp, 2)) = dClass(strKey)
- .Range("a" & index + 1) = ""
- End With
- p = p + 1
- End If
- Next
- Sheets(strMonth).Range("a1").CurrentRegion.EntireColumn.AutoFit
- Next
-
- Application.CutCopyMode = False
- With Application
- .ScreenUpdating = True
- .DisplayAlerts = True
- .AskToUpdateLinks = True
- .Calculation = xlCalculationAutomatic
- End With
- MsgBox "ok"
- End Sub
复制代码 |
|