Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-22-2023, 01:54 PM
Marrick13 Marrick13 is offline Sort Userform Labels Using Array Data Not Working Windows XP Sort Userform Labels Using Array Data Not Working Office 2010 32bit
Competent Performer
Sort Userform Labels Using Array Data Not Working
 
Join Date: Jun 2006
Posts: 103
Marrick13 will become famous soon enough
Default Sort Userform Labels Using Array Data Not Working

I am trying to arrange 10 label controls on a userform alphabetically (ascending or descending) according to what a user would enter in the captions. The attached form shows the labels and has the code I’ve been working with.



The code loops through the form’s controls, identifies the ‘label’ controls, and enters their captions in an array. This seemed to work well when I was just displaying the results in a msgbox, but when I tried to add code that sorts the array alphabetically so the macro could then change the label captions to display in alpha order, this works the first time the Sort function is run when the form opens, but after that, changing the sort option (ascending to descending or vice versa) in the same userform session skews the results, adds spaces between the array elements, and generally becomes a mess.

I thought this might be due to values of variable or objects carrying over from the previous Sort run, but every time I’ve set them to zero, nothing, or ““, I get the same skewed results.

While preparing this version for the Forum, I was getting an error on the ‘If frmMultiClickWrite.LblLabel2.Caption <> ““ Then frmMultiClickWrite.LblLabel2.Caption = MyArray(2 - 1)’ statement in the ‘Sort’ module. But now it sometimes produces the “An error occurred while loading this document” message, which means I have to shut down Word. This is a new error but with my limited VBA experience, I cannot look at the code and determine why this is happening, or why the resulting msgbox text and label captions worked on the first try and not afterwards, or why I’m not getting the “An error occurred while loading this document” error. Can anyone help me out?

Userform and code are attached.
Attached Files
File Type: docm Sort Userform Labels Using Array Data.docm (36.5 KB, 8 views)
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 07:18 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