此函数可显示数据透视表数据源,包括外部数据源。(欢迎大家测试指正)
num参数为当前表中的数据透视的索引号,一般情况下只有一个,填入1即可。
Public Function Sourcedate(num As Integer)
Application.Volatile
On Error GoTo Err
Dim sdarray As Variant
sdarray = ActiveSheet.PivotTables(num).SourceData
If VarType(sdarray) = 8 Then
Sourcedate = sdarray
Else
Sourcedate = ""
For i = LBound(sdarray) To UBound(sdarray)
Sourcedate = Sourcedate & sdarray(i) & " "
Next i
End If
Err:
If Err.Number <> 0 Then
Sourcedate = "没有你要查找的数据透视表!"
End If
End Function
'改变数据源自定义函数(不含外部数据源)
Public Function UpdateSourcedate(Sourcetxt As Variant, num As Byte)
'Application.Volatile
On Error GoTo Err
With ActiveSheet.PivotTables(num).PivotCache
.SourceData = Sourcetxt
.Refresh
UpdateSourcedate = True
End With
Err:
If Err.Number <> 0 Then
UpdateSourcedate = False
End If
End Function
事例附件:
Y0azAvh5.rar
(10.88 KB, 下载次数: 53)
[此贴子已经被作者于2005-8-18 14:32:45编辑过] |