Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 11-24-2023, 07:34 PM
gmaxey gmaxey is offline Sort Userform Labels Using Array Data Not Working Windows 10 Sort Userform Labels Using Array Data Not Working Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 

Tags
array, word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort Userform Labels Using Array Data Not Working 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 Userform Labels Using Array Data Not Working Sort option is not working Francois-Spain Excel 7 06-27-2019 11:04 AM
Sort Userform Labels Using Array Data Not Working 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft