1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
Solution ID: 
 100006382 
Product: 
 SPSS Base  
Version: 
 8.0 
O/S: 
 WINDOWS 
Question Type: 
 Syntax/Batch/Scripting 
Question Subtype: 
  


Title:
Ungroup a Column such As "Valid" In PivotTable Output 

Description:
Q. 
I am using SPSS 8.0 For Windows, And I don't want the column labelled "Valid" to 
be In my frequency tables. "Valid" Is a group label. Is there a script which will 
ungroup these rows? 

A. 
The subroutine UnGroupRows will search For a Text String (such As 
"Valid") In row labels. Another subroutine, UnGroupColumns, will 
search colunm labels. When the requested label Is found, it selects 
it And ungroups it, (much As a user would). 

To Call the subroutines from an autoscript routine: 
1. Paste the subroutines UnGroupRows And/Or UnGroupColumns 
into your Autoscript.sbs file (at the End Is fine). 
2. Right-click On the table And Choose Create/Edit Autoscript from 
the context menu. 
3. Choose Create/Edit Autoscript And To the subroutine which the 
cursor Is placed In, add 

Dim objPivot As PivotTable 
Set objPivot = objTable 
UnGroupRows objPivot, "Valid" 

Check the Edit->Options Dialog's Script tab, to be sure that the 
routine Is enabled: there should be an X In the CheckBox In front of 
the routine's name. 

Here Is how the modified autoscript routine might look: 
_______________________________________________________ 

Sub Frequencies_Table_Frequencies_Create(objTable As Object, _ 
objOutputDoc As Object, lngIndex As Long) 
'Autoscript 
'Trigger Event: Frequencies Table Creation after running Frequencies 
procedure. 

'Effects: Goes through the Row Labels and finds "Total" rows 
'and turns "Total" and associated data cells bold 
Dim bolSelection As Boolean 

Call SelectRowLabelsAndData(objTable, cTOTAL, bolSelection) 
If bolSelection = True Then 
objTable.TextStyle = 2 'make text bold 
End If 

'--- this part was added to hide columns labelled "Frequency" --- 
Dim objPivot As PivotTable 
Set objPivot = objTable 
UnGroupRows objPivot, "Valid" 
End Sub 

_______________________________________________________ 

If you are creating an Autoscript routine, scroll down Until you find 
directions, And paste the indicated portion. 
_______________________________________________________ 

The following Is a simple demonstration of how To Call HideColumn from 
another routine. It can be applied To every PivotTable In the Output; 
see the SPSS Script eXchange at 
http://www.spss.com/software/spss/base/Win75/SCPTXCHG.html 
For further examples. Save the Text below To a script named 
"HideColumn.SBS" ,Select a PivotTable, And Then run the script. 
_______________________________________________________ 

'***** Demo of UnGroupRows and UnGroupColumns ***** 
'--- save everything below to a file "HideColumn.SBS" 
' select a pivot table and run the script 
'***** do not copy Sub Main into an autoscript; see below ***** 

Sub Main 
Dim objPivot As PivotTable 
Dim objItem As ISpssItem 

Dim bolFoundOutput As Boolean, bolFoundPivot As Boolean 

GetFirstSelectedPivot objPivot, objItem, bolFoundOutput, bolFoundPivot 
If Not (bolFoundOutput And bolFoundPivot) Then 
Exit Sub 
End If 

UnGroupRows objPivot, "Valid" 

objItem.Deactivate 
End Sub 

'************************************************************** 
'TO USE IN AN AUTOSCRIPT: 
'Click on Create/Edit Autoscript 
'Call UnGroupRows and/or UnGroupColumns from the 
'routine it creates, as described in the notes. 
'************************************************************** 

'************************************************************** 
'--- paste everything below into Autoscript.sbs, at the end --- 
'************************************************************** 
' 
'HideRowLabelColumn and HideColumnLabelColumn 
'search for the requested label, and hide the 
'column in which it is found. 

Sub UnGroupRows(objPivot As PivotTable, strLabel As String) 
Dim objRowLabels As ISpssLabels 
Dim i As Integer, j As Integer 

Set objRowLabels = objPivot.RowLabelArray 
With objRowLabels 
For i = .NumRows - 1 To 0 Step -1 
For j = 0 To .NumColumns - 1 
If Not IsNull(.ValueAt(i,j)) Then 
If .ValueAt(i,j) = strLabel Then 
objPivot.UpdateScreen = False 
'15 is the minimum value for RowLabels 
.SelectLabelAt(i,j) 
objPivot.Ungroup 
objPivot.UpdateScreen = True 
Exit Sub 
End If 
End If 
Next 
Next 
End With 
End Sub 

Sub UnGroupColumns(objPivot As PivotTable, strLabel As String) 
Dim objColumnLabels As ISpssLabels 
Dim i As Integer, j As Integer 

Set objColumnLabels = objPivot.ColumnLabelArray 
With objColumnLabels 
For i = .NumRows - 1 To 0 Step -1 
For j = 0 To .NumColumns - 1 
If Not IsNull(.ValueAt(i,j)) Then 
If .ValueAt(i,j) = strLabel Then 
objPivot.UpdateScreen = False 
.SelectLabelAt(i,j) 
objPivot.Ungroup 
objPivot.UpdateScreen = True 
Exit Sub 
End If 
End If 
Next 
Next 
End With 
End Sub 

Created On: 05/24/1999