DoubleClick on row in ListBox on UserForm

Grz3siu

New Member
Joined
Apr 21, 2015
Messages
7
Hello
In UserForm I have a ListBox, I would like that ListBox’s data source were coming from separate spreadsheet called “test” Address to this spreadsheet would be kept in cell A2 of “data” spreadsheet where ListBox is created on. In addition I need user to be able to double click on UserForm row in order to see message box with value from 1st cell of it. Screenshots of desired outcome below.
belllow.png


Code:
Dim SourceWB As WorkbookDim ListItems As Variant


Application.ScreenUpdating = False


Set SourceWB = Workbooks.Open(Sheets("data").Range("A2"), False, True)


ListItems = SourceWB.Worksheets(2).Range("B1:AM3")
' here I am collecting data directly from the range, I would like it to be fetched from the table named "Table2"
With Me.ListBox1
    .List = ListItems
    .ColumnCount = 5
End With


SourceWB.Close False
Set SourceWB = Nothing


Application.ScreenUpdating = True
Hope you can help!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I found a solution, but there is still a small problem, because it returns me 38 times. Below is the code, if someone wants to come close. Write if you can solve the problem with the amount of returned value.
msgbox.png


Code:
Dim SourceWB As WorkbookDim ListItems As Variant


Application.ScreenUpdating = False


Set SourceWB = Workbooks.Open(Sheets("Secret").Range("CE2"), False, True)


'ListItems = SourceWB.Worksheets(2).Range("Tabela2")
ListItems = SourceWB.Worksheets(2).Range("B1:AM3")
With Me.ListBox1
    .List = ListItems
    .ColumnCount = 38
End With


SourceWB.Close False
Set SourceWB = Nothing


Application.ScreenUpdating = True


and

Code:
Dim I As LongDim msg As String
 
    If ListBox1.ListIndex <> -1 Then
        For I = 0 To ListBox1.ColumnCount - 1
            msg = msg & ListBox1.Column(7) & vbCrLf
        Next I
    End If
MsgBox msg
 
Upvote 0
Loop is not required if you only want the message once:

Code:
If ListBox1.ListIndex <> -1 Then MsgBox = ListBox1.Column(7) & vbCrLf
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
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