04 Pivot - AndrewMB2/Logic-Architect-for-Excel-VBA GitHub Wiki

Pivot method

Pivots data in an ArrData object. Returns True if successful, otherwise False.

Applies to

TableData ArrData RsetData Xdata XShared

Parameters

Name Type Description
PivotField Variant Name or number of the field whose values will be transferred to new fields.
DataField Variant Name or number of the field which supplies the data values for the new fields.

Pivot can be used to create a crosstab by adding a field for every unique value of the pivot field and populating the data with values from the data field, for each set of unique values of the remaining fields. The pivot and data field are dropped.

There must be only one value in each case, so if multiple values are to be accumulated, run a Group first. However this does allow the data field to be of any data type including text.

Fields are added in the sequence in which they are encountered, so to get these in alpha sequence, first sort the data on the pivot field. It can then be resorted after the pivot operation into whatever sequence is required.

If the pivot field is a date, this is output in yyyy-mm-dd format when the new fields are created.