Question : get address from listbox

Hi,

I have a listbox with values from a range (excel cells)
The listbox is dynamic, which means it is filtered when something is typed in a textbox.

Everything works thanks to some of you :)

But now:
When double clicked on an item, I want the address of the cells (row number is more than enough)  to show up in a msgbox

Fyi not the row of the listbox, but the row of the excel table
(Ill use that address for otrher means)

Answer : get address from listbox

Something like the code below then (adjust the column widths as required)
Note: it's air code, so test!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
'
'-----------
'FILTER CODE
'-----------
'
Private Sub txt_zoeken_Change()
    ' note: this assumes your listbox has 4 columns!
    
    Dim lngLastRow As Long, lngRow As Long, lngCol As Long
    Dim wks As Worksheet
    Dim varData As Variant
    Set wks = Workbooks("Klanten.xls").Sheets("Klant")
    lst_klanten.Clear
    If Len(txt_zoeken.text) > 0 Then
        lngLastRow = wks.Cells(Rows.Count, "A").End(xlUp).row
        ' load data from sheet into array (faster than reading cells)
        varData = wks.Range("B1:E" & lngLastRow).Value
        ' now loop through array
        For lngRow = 2 To lngLastRow
            For lngCol = 1 To 4
                ' check for text
                If InStr(1, varData(lngRow, lngCol), txt_zoeken.text, vbTextCompare) > 0 Then
                    ' found, so add data
                    With lst_klanten
                        .AddItem varData(lngRow, 1)
                        .List(.ListCount - 1, 1) = varData(lngRow, 2)
                        .List(.ListCount - 1, 2) = varData(lngRow, 3)
                        .List(.ListCount - 1, 3) = varData(lngRow, 4)
                        .List(.ListCount - 1, 3) = lngRow
                    End With
                    ' text found, no need to check more columns
                    Exit For
                End If
            Next lngCol
            ' do next row of array
        Next lngRow
    Else
        Call PopulateListClients
    End If
End Sub
'
'------------
'POPULATELIST
'------------
'
Sub PopulateListClients()
    Dim lbtarget As MSForms.ListBox
    Dim rngSource As Range
    Dim LastRow As Integer, n as Long
    Dim varData
    LastRow = Workbooks("Klanten.xls").ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).row
    'Set reference to the range of data to be filled
    Set rngSource = Workbooks("Klanten.xls").Worksheets("Klant").Range("B2:E" & LastRow)
    varData = rngsource.Value
    'Fill the listbox
    Set lbtarget = Me.lst_klanten
    With lbtarget
        .Clear
        'Determine number of columns
        .ColumnCount = 5
        'Set column widths
        .Columnwidths = "75 pt;75 pt;75 pt;75 pt;0 pt"
        'Insert the range of data supplied
        for n = 1 to LastRow - 1
           .AddItem vardata(n, 1)
           .List(n - 1, 1) = varData(n, 2)
           .List(n - 1, 2) = varData(n, 3)
           .List(n - 1, 3) = varData(n, 4)
           .List(n - 1, 4) = n + 1
        next n 
    End With
End Sub
Random Solutions  
 
programming4us programming4us