Return to the original row with a listbox from a userform

Doflamingo

Board Regular
Joined
Apr 16, 2019
Messages
238
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 ?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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
 
Upvote 0
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 [h=2]to Return to the original row for a very long text in a listbox [/h]
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 ?
 
Upvote 0
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.
 
Upvote 0
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/gdibhibnztthfme/Macro Listbox expand.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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top