How to sort in ascending order in a comboBox

Solved
Flow -  
 Flow -
Hello everyone,

I created a program that gives me the coordinates of each client based on the number of days until the next maintenance, and I have a question because I can't sort my numbers in the comboBox in ascending order.

Could you please help me?

Thank you,

1 answer

  1. cs_Le Pivert Posted messages 8437 Status Contributor 730
     
    Hello,

    see this:

    https://excel.developpez.com/faq/?page=OleObject#TriAlphaComboBox

    Sub SortAlpha_ComboBox() Dim i As Integer, j As Integer Dim strTemp As String 'Clear the ComboBox content ComboBox1.Clear 'Fill the ComboBox ComboBox1.List() = Array("5", "2", "4", "3", "1") 'Sort the ComboBox content in alphabetical order With ComboBox1 For i = 0 To .ListCount - 1 For j = 0 To .ListCount - 1 If .List(i) < .List(j) Then strTemp = .List(i) .List(i) = .List(j) .List(j) = strTemp End If Next j Next i End With End Sub


    --
    @+ The Woodpecker
    0
    1. Flow
       
      Thank you very much, it works perfectly.

      I have one last small question.

      I have a textbox where the date is displayed like this: d/m/yyyy (for example: 3/9/2016)

      Is there a way to display it in the format: dd-mm-yyyy (for example: 03 September 2016)?

      Thank you again,
      0
    2. cs_Le Pivert Posted messages 8437 Status Contributor 730
       




      Dim date_test As Date date_test = Now() TextBox1.Text = WorksheetFunction.Proper(Format(date_test, "dddd d mmmm yyyy")) 


      @+ The Woodpecker
      0
    3. Flow
       
      I have executed the code below, it corresponds to my TextBox6:

      Private Sub TextBox6_Change()
      TextBox6.Text = WorksheetFunction.Proper(Format(TextBox6.Text, "dddd d mmm yyyy"))
      End Sub

      However, the date is incorrect, maintenance is supposed to be performed in 19 days, and it displays Friday, June 3, 2016, as if a base offset is being taken into account.

      Do you have any idea where this might be coming from?

      Thank you again;
      0
    4. cs_Le Pivert Posted messages 8437 Status Contributor 730
       
      when you click in the TextBox the date updates:

      Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) TextBox1.Text = WorksheetFunction.Proper(Format(TextBox1.Text, "dddd d mmm yyyy")) End Sub 
      0
    5. Flow
       
      It's perfect, thank you very much, I think you are the creator of VBA ^^

      Good evening
      0