View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
peterDavey peterDavey is offline
external usenet poster
 
Posts: 6
Default Sort multicolumn listbox items?

Jens,
the following code loads a multi-column list box with the names and number
formats of the data fields of a pivot table. The trick is to load the data
into an array variable first the assign that array to the list box List
property: E.g. Me.lstDataItem.List() = varListArray.

The data could just as easily be read from an Excel range.

cheers
peterDavey
Melbourne

Public Sub LoadDataItemList()

Dim varListArray() As Variant
Dim objPivotTable As PivotTable
Dim objPivotField As PivotField
Dim intRow As Integer

Set objPivotTable = Me.PivotTables(1)
' re-dimension the array to the number of items in the DataFields
collection.
ReDim varListArray(objPivotTable.DataFields.Count - 1, 1)

Me.lstDataItem.Clear
intRow = 0
For Each objPivotField In objPivotTable.DataFields
varListArray(intRow, 0) = objPivotField.Name
varListArray(intRow, 1) = objPivotField.NumberFormat
intRow = intRow + 1
Next objPivotField
Me.lstDataItem.List() = varListArray
Me.lstDataItem.ListIndex = 0

End Sub


"Jens Meier" wrote in message
...
Hello everybody,

on a UserForm, I have got a multicolumn ListBox.

Is there a possibility to let Excel sort the listbox items after a click
on the column headers, taking that column as the search criteria?

Btw, another question: is it possible to fill a multicolumn listbox out
of an array variable, without the need to specify a RowSource from a
worksheet?

Thank you in advance,
Jens