VBA/pivot.bas

108 lines
2.3 KiB
QBasic
Raw Normal View History

2019-03-05 16:18:02 -05:00
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
2019-03-14 14:44:23 -04:00
Attribute VB_Name = "pivot"
2019-03-05 16:18:02 -05:00
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
2019-02-27 19:50:49 -05:00
Option Explicit
2019-03-05 11:41:11 -05:00
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
2019-02-27 19:50:49 -05:00
2019-03-05 11:41:11 -05:00
If Intersect(Target, ActiveSheet.Range("b7:v100000")) Is Nothing Then
2019-02-27 19:50:49 -05:00
Exit Sub
End If
On Error GoTo nopiv
If Target.Cells.PivotTable Is Nothing Then
Exit Sub
End If
2019-01-16 14:48:19 -05:00
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
2019-02-27 19:50:49 -05:00
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim wapi As New Windows_API
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
2019-02-27 19:50:49 -05:00
ReDim handler.sc(ri.Count, 1)
Set pt = Target.Cells.PivotCell.PivotTable
handler.sql = ""
handler.jsql = ""
For i = 1 To ri.Count
2019-02-27 19:50:49 -05:00
If i <> 1 Then handler.sql = handler.sql & vbCrLf & "AND "
If i <> 1 Then handler.jsql = handler.jsql & vbCrLf & ","
handler.sql = handler.sql & rd(piv_pos(rd, i)).Name & " = '" & ri(i).Name & "'"
jsql = jsql & """" & rd(piv_pos(rd, i)).Name & """:""" & ri(i).Name & """"
handler.sc(i - 1, 0) = rd(piv_pos(rd, i)).Name
handler.sc(i - 1, 1) = ri(i).Name
Next i
2019-02-27 19:50:49 -05:00
scenario = "{" & handler.jsql & "}"
2019-03-14 14:44:23 -04:00
Call handler.load_config
2019-02-27 19:50:49 -05:00
Call handler.load_fpvt
2019-03-14 14:44:23 -04:00
2019-02-27 19:50:49 -05:00
nopiv:
End Sub
Function piv_pos(list As Object, target_pos As Long) As Long
2019-02-27 19:50:49 -05:00
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
2019-02-27 19:50:49 -05:00
End Function
Function piv_fld_index(field_name As String, ByRef pt As PivotTable) As Integer
Dim i As Integer
For i = 1 To pt.PivotFields.Count
If pt.PivotFields(i).Name = field_name Then
piv_fld_index = i
Exit Function
End If
Next i
End Function
2019-02-27 19:50:49 -05:00
2019-03-05 11:41:11 -05:00
2019-03-14 14:44:23 -04:00