How should I make a ListBox in Excel into a Date Sorce?

Testested 61 Reputation points
2022-10-23T22:19:58.35+00:00

How should I make a List Box in Excel into a Date Sorce?

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,511 questions
Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,645 questions
{count} votes

Accepted answer
  1. Oskar Shon 866 Reputation points MVP
    2022-12-04T18:50:25.767+00:00

    aaa long time... and easy answer using code write up... hmm
    ok learn

     Dim x&, y&  
     For x = 1 To ListBox1.ColumnCount  
           For y = 1 To ListBox1.ListCount  
                If x = 1 Then Cells(y, 2) = ListBox1.List(y - 1, x - 1)  
                If x = 2 Then Cells(y, 1) = ListBox1.List(y - 1, x - 1)  
           Next  
     Next  
    

    X variable I using for columns, then switch that is a easy job to do. Its done.

    So exercise for you now - you must read about that and make it.
    If you had a more than 2 columns in control, learn about back loop without condition, to switch it opposite count. Do you?


6 additional answers

Sort by: Most helpful
  1. Oskar Shon 866 Reputation points MVP
    2022-11-24T19:38:54.853+00:00

    Usually 1st is 1st.
    So you should do the loop, counting maximum column and rows like:

    Dim x&, y&  
    For x = 1 To ListBox1.ColumnCount  
          For y = 1 To ListBox1.ListCount  
                Cells(y, x) = ListBox1.List(y - 1, x - 1)  
          Next  
    Next  
    

    That control start from 0 so you can do it like I do (-1) or +1 like below

    Dim x&, y&  
    For x = 0 To ListBox1.ColumnCount -1  
          For y = 0 To ListBox1.ListCount -1  
                Cells(y +1, x+1) = ListBox1.List(y, x )  
          Next  
    Next  
    

    I you like switch columns then you should write condition if() - try to do that - can you?

    Regards


  2. Testested 61 Reputation points
    2022-11-24T22:32:38.853+00:00

    @Oskar Shon ,

    I am not having luck with the two examples posted. Not sure how to use if() in this condition. Please advise. Thanks.