-1
任何人都可以看到为什么这不适合我吗?为什么这个简单的VBA代码不起作用
我的单元格H6包含一个12位数字,因此使用Long。 如何为了调整这个代码,它的工作有什么想法:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cell'H6 or H7 is touched
If Intersect(Target, Range("H6:H7")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As Long
'Here you amend to suit your data
Set pt = Worksheets("Data1").PivotTables("PivotTable10")
Set Field = pt.PivotFields("[Produkter].[EAN].[EanID]")
NewCat = Worksheets("Data1").Range("H6").Value
'This updates and refreshes the PIVOT table
With ActiveSheet.PivotTables("PivotTabel10").PivotFields("[Produkter].[EAN].[EanID]")
.ClearAllFilters
.PivotFilters.Add Type:=xlCaptionEquals, Value1:=ActiveSheet.Range("H6").Value
End With
这段代码应该做什么?现在在做什么?你有错误信息吗?你有[参观](http://stackoverflow.com/tour)? – steenbergh
试着更好地描述你的代码中发生了什么,你试图达到什么目标,以及你在哪一行发生错误。目前状态的帖子不能告诉我们很多,这几乎不可能帮助你 –
对不起。 我希望能够在单元格H6中输入12位数字,以便数据透视表中的过滤器将更改为该数字。我得到了一些不同的错误,但最常见的是:运行时错误6溢出。 –