|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
原帖由 piny 于 2010-10-3 23:57 发表
F9是自动重算的意思
基本上 1000行的数据 用公式本来就快不了
若要追求效率 请至vba板求助
Sub PVT_ABC()
t = Timer
r = [a1].End(4).Row
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="数据DATA!R1C1:R" & r & "C4").CreatePivotTable TableDestination:="", TableName:="表ABC"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.PivotTables("表ABC").RowGrand = False
ActiveSheet.PivotTables("表ABC").AddFields RowFields:=Array("A", "选择题序号")
ActiveSheet.PivotTables("表ABC").PivotFields("选择题序号").Orientation = xlDataField
ActiveSheet.PivotTables("表ABC").PivotFields("求和项:选择题序号").Function = xlCount
DataCopy
ActiveSheet.PivotTables("表ABC").PivotFields("A").Orientation = xlHidden
With ActiveSheet.PivotTables("表ABC").PivotFields("B")
.Orientation = xlRowField
.Position = 1
End With
DataCopy
ActiveSheet.PivotTables("表ABC").PivotFields("B").Orientation = xlHidden
With ActiveSheet.PivotTables("表ABC").PivotFields("C")
.Orientation = xlRowField
.Position = 1
End With
DataCopy
Application.CommandBars("PivotTable").Visible = False
Application.DisplayAlerts = False
'On Error Resume Next
ActiveWindow.SelectedSheets.Delete
MsgBox "处理 " & r - 1 & " 行数据,耗时 " & Timer - t & " 秒。"
End Sub
Sub DataCopy()
If Right(Range("C4").End(4).Offset(-1, -2), 2) = "汇总" Then Range("C4").End(4).Offset(-1, -2).Delete
Range("A5").Select
Sheets(Range("A4").Value).Range("A1").CurrentRegion.ClearContents
Do Until ActiveCell = "总计"
Sheets(Range("A4").Value).Range("A1").Offset(0, m) = ActiveCell & "-" & Range("A4")
n = 1
Do
If ActiveCell.Offset(n, 0) = "" Then
n = n + 1
ElseIf ActiveCell.Offset(n - 1, 0) <> ActiveCell.Offset(n, 0) Then
Exit Do
End If
Loop
Sheets(Range("A4").Value).Range("A1").Offset(1, m).Resize(n, 1).Value = ActiveCell.Offset(0, 1).Resize(n, 1).Value
m = m + 1
ActiveCell.Offset(n, 0).Select
Loop
End Sub
如果需要知道甲或乙各选择了几个1、几个2……,还需要改进。
但是不知道楼主要不要,要的话数据放哪里? |
|