如果我在下面的数据透视表中选择其中一个数据透视表,有没有办法确定它的位置?例如,选择Yc并推断位置为2。
Xa
---- Yb
---- Yc
-------- Za
-------- Zb
-------- Zc
Xb
---- Yd
-------- Ze
-------- Z5
答案 0 :(得分:1)
关键是确保您处于正确的范围内。在pivot table ranges上查看Jon Peltier的精彩页面。在您的情况下,您希望将单元格选择限制为RowFields
。确定从Item
中Field
Option Explicit
Sub WhatPosition()
Dim pt As PivotTable
Set pt = ActiveSheet.PivotTables(1)
Debug.Print "current cell selection is " & Selection.Address & _
" = '" & Selection.value & "'"
'--- is the selection within the row label range of the pivot table?
If Not Intersect(Selection, pt.RowRange) Is Nothing Then
Debug.Print "selection position = " & StringToPivotFieldPosition(pt, Selection.value)
Else
Debug.Print "the selection is not within the pivot table"
End If
End Sub
Private Function StringToPivotFieldPosition(ByRef pTable As PivotTable, _
ByVal value As String) As Long
Dim field As PivotField
StringToPivotFieldPosition = 0
For Each field In pTable.RowFields
Dim item As PivotItem
For Each item In field.PivotItems
If item.Name = value Then
StringToPivotFieldPosition = field.position
Exit Function
End If
Next item
Next field
End Function
中哪个位置退出的路径
cants_field_visible.addEventListener "keyup", ->
calculate_carbohydrates.call(this, "#{if id == undefined then item_id else id}", "#{if carbohydrates == undefined then item_carbohydrates else carbohydrates}")