![]() |
|
|
|
#1
|
|||
|
|||
|
Code:
Private Sub cmdSort_Click()
Dim lngIndex As Long, lngLblCount As Long
Dim j As Long
Dim oColLbls As New Collection
ReDim arrCaps(0)
For Each oCtrl In Controls
'Filter for specific type
If TypeName(oCtrl) = "Label" Then
'Add to collection and index label counter
oColLbls.Add oCtrl
lngLblCount = lngLblCount + 1
If oCtrl.Caption <> "" Then
'Dimension, add to array and index counter
ReDim Preserve arrCaps(lngIndex)
arrCaps(lngIndex) = Trim(oCtrl.Caption)
lngIndex = lngIndex + 1
End If
End If
Next oCtrl
For lngIndex = LBound(arrCaps) To UBound(arrCaps) - 1
For j = lngIndex + 1 To UBound(arrCaps)
If frmMultiClickWrite.optAscending.Value = True Then
If arrCaps(lngIndex) > arrCaps(j) Then '>' for ascending
Temp = arrCaps(j)
arrCaps(j) = arrCaps(lngIndex)
arrCaps(lngIndex) = Temp
End If
End If
If frmMultiClickWrite.optDescending.Value = True Then
If arrCaps(lngIndex) < arrCaps(j) Then '<' for descending
Temp = arrCaps(j)
arrCaps(j) = arrCaps(lngIndex)
arrCaps(lngIndex) = Temp
End If
End If
Next j
Next lngIndex
'Clear captions
For lngIndex = 1 To lngLblCount
oColLbls(lngIndex).Caption = vbNullString
Next lngIndex
'Add sorted captions
For lngIndex = 0 To UBound(arrCaps)
oColLbls(lngIndex + 1).Caption = arrCaps(lngIndex)
Next lngIndex
lbl_Exit:
Exit Sub
End Sub
|
|
#2
|
|||
|
|||
|
Greg,
Your code is wonderful -- just what I wanted. Thanks so much! I never thought of using a collection, or putting controls into it, but then, I'm not a developer, either (and rather poor at constructing arrays, even though they are quite powerful). Thank you again -- I really appreciate your help! |
|
| Tags |
| array, word vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
VBA help non breaking spaces for array of words not working correctly
|
Shelley Lou | Word VBA | 2 | 03-08-2023 03:15 AM |
| Sort option is not working | Francois-Spain | Excel | 1 | 07-04-2019 02:01 AM |
Sort option is not working
|
Francois-Spain | Excel | 7 | 06-27-2019 11:04 AM |
How do I make a checkbox or dropdown item reference data in that specific section of the data array?
|
dhare | Excel Programming | 2 | 02-24-2016 12:36 PM |
| Powerpoint: adding data to trend lines w/o data labels | HaiLe | PowerPoint | 0 | 04-11-2011 09:21 AM |