Return to the original row with a listbox from a userform
Results 1 to 8 of 8

Thread: Return to the original row with a listbox from a userform
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Apr 2019
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Return to the original row with a listbox from a userform

    Hi all, I wondered how to Return to the original row with a listbox

    I know with a short statement that's OK for the listbox for a determined lenght and height, I see the whole statement when I activate the userform.

    Code:
    If OptionButton1.Value = True Then Me.ListBox2.AddItem ("blabla")
    But If I don't want to change the features of the listbox and keep the same height and lenght

    If I have a long statement, it does not fully appear in the listbox when the userform is activated.

    Like

    Code:
    If OptionButton2.Value = True Then Me.ListBox2.AddItem ("blablaasdfghjklqwertyuiopfghjkwertyuiasdfghjk")
    So, does anyone know how to Return to the original row with a listbox ?

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,315
    Post Thanks / Like
    Mentioned
    50 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Return to the original row with a listbox from a userform

    Try this
    When you move the mouse to the listbox, its width automatically increases. When you remove the mouse, it automatically returns to its original size.

    Code:
    Dim LWidth  'At the beginning of all the code
    
    
    Private Sub ListBox2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        ListBox2.Width = 200
    End Sub
    
    
    Private Sub UserForm_Activate()
        LWidth = ListBox2.Width
    End Sub
    
    
    Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        ListBox2.Width = LWidth
    End Sub
    Regards Dante Amor

  3. #3
    Board Regular
    Join Date
    Apr 2019
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Return to the original row with a listbox from a userform

    Many Thanks @DanteAmor for your reply.

    Indeed that works , the listbox expands to the right direction, however it still does not allow to display all the text in the listbox, even if it's better than before.

    Actually rather than expand the width of the listbox, because unfortunately I can't expand endlessly the width of the userform, I really look for a code that would allow me to Return to the original row for a very long text in a listbox

    for the VBA code, you can use " _" and then to the next row "&"
    but for a very long text included in a listbox, when the userform is activate, how to Return to the next row ?

  4. #4
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,315
    Post Thanks / Like
    Mentioned
    50 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Return to the original row with a listbox from a userform

    Quote Originally Posted by Doflamingo View Post
    Many Thanks @DanteAmor for your reply.

    Indeed that works , the listbox expands to the right direction, however it still does not allow to display all the text in the listbox, even if it's better than before.

    Actually rather than expand the width of the listbox, because unfortunately I can't expand endlessly the width of the userform, I really look for a code that would allow me to Return to the original row for a very long text in a listbox


    for the VBA code, you can use " _" and then to the next row "&"
    but for a very long text included in a listbox, when the userform is activate, how to Return to the next row ?

    In a ListBox control you can only have one row per field.
    I think I'm not really understanding what the problem is.
    Do you have a ListBox or a TextBox?
    In the listbox, when the length of the text is longer, the scroll bar is activated automatically, so that you scroll horizontally.
    Regards Dante Amor

  5. #5
    Board Regular
    Join Date
    Apr 2019
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Return to the original row with a listbox from a userform

    Hello @DanteAmor,
    Many thanks for your reply and sorry for mine which is quite late
    Please find enclosed the Excel Workbook with the macro you gave me.

    https://www.dropbox.com/s/gdibhibnzt...pand.xlsm?dl=0


    Indeed for the Optionbutton1, that’s Ok given that the text related is short
    But for the Optionbutton2, even if the listbox expand,, it does not displays all the text.

    So if you say me, one row in the listbox for 1 statement. So I guess that’s not possible to get what I was looking for: Return to the next row with a listbox for a same statement

    Kind regards

    Doflamingo

  6. #6
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,315
    Post Thanks / Like
    Mentioned
    50 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Return to the original row with a listbox from a userform

    delete the code and use only the following

    Code:
    Private Sub OptionButton1_Click()
    If OptionButton1 = True Then ListBox1.AddItem "blabla"
    End Sub
    
    
    Private Sub OptionButton2_Click()
    If OptionButton2 = True Then ListBox1.AddItem "You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:"
    End Sub
    
    
    Private Sub UserForm_Activate()
     ListBox1.ColumnWidths = "1000"
    End Sub
    Regards Dante Amor

  7. #7
    Board Regular
    Join Date
    Apr 2019
    Posts
    165
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Return to the original row with a listbox from a userform

    Hello @DanteAmor

    I've erased the old code and replaced it with the new one you gave me.

    That a srcoll bar that allows me to see the whole text of the listbox when Optionbutton2 is activated

    Many thanks for your help and time once again

    Kind regards

    Doflamingo

  8. #8
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,315
    Post Thanks / Like
    Mentioned
    50 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Return to the original row with a listbox from a userform

    Quote Originally Posted by Doflamingo View Post
    Hello @DanteAmor

    I've erased the old code and replaced it with the new one you gave me.

    That a srcoll bar that allows me to see the whole text of the listbox when Optionbutton2 is activated

    Many thanks for your help and time once again

    Kind regards

    Doflamingo

    Youre welcome, thanks for the feedback.
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •