start work on building an sql filter for a pivot table selection
This commit is contained in:
parent
f546f7c7d1
commit
144c0f85db
51
pivot.bas
Normal file
51
pivot.bas
Normal file
@ -0,0 +1,51 @@
|
||||
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
|
||||
|
||||
Cancel = True
|
||||
|
||||
Dim i As Long
|
||||
Dim j As Long
|
||||
Dim k As Long
|
||||
|
||||
Dim ri As PivotItemList
|
||||
Dim ci As PivotItemList
|
||||
Dim df As Object
|
||||
Dim rd As Object
|
||||
Dim cd As Object
|
||||
Dim dd As Object
|
||||
|
||||
Set ri = Target.Cells.PivotCell.RowItems
|
||||
Set ci = Target.Cells.PivotCell.ColumnItems
|
||||
Set df = Target.Cells.PivotCell.DataField
|
||||
|
||||
Set rd = Target.Cells.PivotTable.RowFields
|
||||
Set cd = Target.Cells.PivotTable.ColumnFields
|
||||
|
||||
Dim sql As String
|
||||
|
||||
For i = 1 To ri.Count
|
||||
If i <> 1 Then sql = sql & vbCrLf & "AND "
|
||||
sql = sql & rd(piv_pos(rd, i)).Name & " = '" & ri(i).Name & "'"
|
||||
Next i
|
||||
|
||||
For i = 1 To ci.Count
|
||||
sql = sql & vbCrLf & "AND "
|
||||
sql = sql & cd(piv_pos(cd, i)).Name & " = '" & ci(i).Name & "'"
|
||||
Next i
|
||||
|
||||
MsgBox (sql)
|
||||
|
||||
End Sub
|
||||
|
||||
Function piv_pos(list As Object, target_pos As Long) As Long
|
||||
Dim i As Long
|
||||
|
||||
For i = 1 To list.Count
|
||||
If list(i).Position = target_pos Then
|
||||
piv_pos = i
|
||||
Exit Function
|
||||
End If
|
||||
Next i
|
||||
'should not get to this point
|
||||
|
||||
|
||||
End Function
|
Loading…
Reference in New Issue
Block a user