+ Reply to Thread
Results 1 to 11 of 11

Listbox showing data searched in a sheet using the given combobox value

  1. #1
    Registered User
    Join Date
    11-09-2017
    Location
    Hamburg
    MS-Off Ver
    Mac 2011
    Posts
    7

    Listbox showing data searched in a sheet using the given combobox value

    Hi everyone,

    I'm facing a very hard (for me) issue. Ok this is my situation:

    1. my worksheet has 7 sheets, let's say DE, E, DU, U, RI, Look, M

    in sheet DE I have the following data:
    COL
    ROW A B C D E F
    1 Name Invoice num Invoice date Value When due when paid
    2 John 1 01.01.17 100 01.01.17 01.01.17
    3 Bill 2 01.02.17 200 01.02.17 01.01.17
    4 Howard 3 01.03.17 300 01.03.17
    5 Mary 4 01.04.17 150 01.04.17
    6 Tina 5 01.01.17 50 01.01.17 01.01.17
    7 Bill 6 01.07.17 170 01.07.17
    8 John 7 01.03.17 100 01.03.17 01.01.17
    9 Mary 8 01.02.17 100 01.02.17

    where the name in A are set from the sheet Look, which has:

    COL
    ROW A
    1 Name
    2 John
    3 Bill
    4 Mary
    5 Howard

    So column A in sheet "Look" has a order list of unique name
    Sheet DE is where I register all the invoices. So I could have, in column A, the same more times.

    My issue

    I created an UserForm like the following:

    Userform1
    Combobox1
    ListBox1

    and I would like that ComboBox1 is populated by the list in column A of sheet "Look" (I menaged it, more or less) and then ListBox1 is populated with all the invoices which are not paid (so with column F empty) of the given data in ComboBox1 searched in the sheet "DE".
    To better explain, if in ComboBox is set the value "John", the listbox will not show anything (all the invoices are paid).
    If combobox shows "Mary", then listbox1 will shows ROW 5 and 9 of the sheet DE.
    What shoudl be the code for that?
    Thank you in advance.
    Giacomo
    Attached Files Attached Files
    Last edited by minominuccio; 11-09-2017 at 11:35 AM.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Listbox showing data searched in a sheet using the given combobox value

    I usually do that like this.

    Set columns of ListBox1 to eight.

    I store the Found record row in the last column, so If you want to change that record, you don't have to look it up again. Set the last Column width to 0 to hide this column.
    E.g. .ColumnWidths = "50;50;50;50;50;50;50;0"

    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    11-09-2017
    Location
    Hamburg
    MS-Off Ver
    Mac 2011
    Posts
    7

    Re: Listbox showing data searched in a sheet using the given combobox value

    Hi Tinbendr,

    thank you for you time.
    I've been trying to check it but I get always:
    "compile error: Invalide use of property" most probably at ".Range ("a1:a" & LastRow)"
    I cannot understand why.
    Giacomo

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Listbox showing data searched in a sheet using the given combobox value

    Make sure you change the name of the worksheets ("DE") to the correct name.

    Make sure it's looking down the correct column ("A").

    LastRow can't be 0. If you're getting 0, then it's likely not searching the correct column.

  5. #5
    Registered User
    Join Date
    11-09-2017
    Location
    Hamburg
    MS-Off Ver
    Mac 2011
    Posts
    7

    Re: Listbox showing data searched in a sheet using the given combobox value

    the Private Sub UserForm_Initialize() has

    ......
    nRiga = Worksheets("Look").Cells(Rows.Count, 1).End(xlUp).Row
    Set Intervallo = Worksheets("Look").Range("a2:a" & nRiga)

    so it searches, as it must be, in the sheet "Look" through the column A.

    the Private Sub ComboBox1_Change() has

    .....
    Set WS = Worksheets("DU") ------>>> it seems correct. I want the the given combobox1 value (got from sheet "Look") search through Column "A" of the sheet "DU"

    So, everything looks fine, cannot figure out the error

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Listbox showing data searched in a sheet using the given combobox value

    Ok, I think I've got it working like you want. At least to where you can view it.

    I randomly changed some of the Due verbs, just so i could see if it was working.

    You really should make a unique list from Column A on DE and NOT a list sheet. If someone is added, you'll have to remember to add them, whereas if you generate a unique list at runtime, the combobox will always have a current list of names.

    Please Login or Register  to view this content.
    P.S. I had to turn off a lot of the References because it keep erroring out on me.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    11-09-2017
    Location
    Hamburg
    MS-Off Ver
    Mac 2011
    Posts
    7

    Re: Listbox showing data searched in a sheet using the given combobox value

    P E R F E C T!!!!!
    I did small changes to best fits by needs but it is ABSOLUTELY PERFECT.
    Thank you a lot.
    I'm not closing the thread since I'm pretty sure i'll need some other help.

  8. #8
    Registered User
    Join Date
    11-09-2017
    Location
    Hamburg
    MS-Off Ver
    Mac 2011
    Posts
    7

    Re: Listbox showing data searched in a sheet using the given combobox value

    Dear Tinbendr,

    one more (last) question.
    In that userform:
    1. I populate the ComboBox with the value of column A in the sheet "Look"--------------> DONE
    2. When selecting one value of the Combobox, that value is searched in the sheet "DU" and copied (filter by the column "F" = "NOT PAID") in the listbox---------------> DONE BY YOU. WORKING PERFECTLY

    Now I would like that, once I select one row in the listbox, by pressing a command button:

    1. a msgbox will ask me to enter a date (done)
    2. once filled the msgbox, that date should be written in the corresponding "F" column of the sheet "DU"

    I attached an example screenshot.
    Thank you in advance
    Attached Images Attached Images

  9. #9
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Listbox showing data searched in a sheet using the given combobox value

    In your 'message box', in the confirmation command button, add

    worksheets("DU").range("F" & Me.ListBox1.Column(7, Me.ListBox1.ListIndex)) = MyDate

    Column 7 is the stored record row value when we initially filled the listbox.
    Last edited by Tinbendr; 11-15-2017 at 09:02 PM.

  10. #10
    Registered User
    Join Date
    11-09-2017
    Location
    Hamburg
    MS-Off Ver
    Mac 2011
    Posts
    7

    Re: Listbox showing data searched in a sheet using the given combobox value

    Master of Disaster!!
    Exactly as expected: perfect !!!!
    Thank you very much

  11. #11
    Registered User
    Join Date
    11-09-2017
    Location
    Hamburg
    MS-Off Ver
    Mac 2011
    Posts
    7

    Re: Listbox showing data searched in a sheet using the given combobox value

    Hi again,

    another issue is stopping me.
    In the Userform8 I'm populating the listbox1 as following:

    Me.ListBox1.ColumnWidths = "100;100;100;100;100;100;100;50"
    Dim WS As Worksheet
    Dim c As Range
    Dim LastRow As Long
    Dim A As Long

    Label5.Visible = True


    Me.TextBox2.Value = ""
    Me.TextBox1.Value = ""





    Me.ListBox1.Clear
    'Me.ComboBox1.Clear

    Set WS = Worksheets("DU")

    With WS
    LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

    With .Range("a2:a" & LastRow - 1)
    Set c = .Find("*", LookIn:=xlValues)
    If Not c Is Nothing Then
    firstAddress = c.Address
    Do
    'If c.Offset(0, Range("F2").Column - 1) = "" Then
    With Me.ListBox1
    'Name
    ' .AddItem c.Offset(0, 0)
    ' .AddItem C.Offset(0, Range("A1").Column - 1)

    'Column B - Invoice Number
    .AddItem c.Offset(0, 1)
    'Invoice Dae

    .Column(0, .ListCount - 1) = c.Offset(0, 0) 'NOME FORNITORE

    .Column(1, .ListCount - 1) = c.Offset(0, 1) 'num fattura
    .Column(2, .ListCount - 1) = c.Offset(0, 2) 'DATA FATTURA
    'Value
    .Column(3, .ListCount - 1) = "Û " & c.Offset(0, 3) 'IMPORTO FATTURA
    'When due
    .Column(4, .ListCount - 1) = c.Offset(0, 4)
    'When Paid
    ' If C.Offset(0, 5) = "" Then
    ' .Column(4, .ListCount - 1) = "No Date"
    'Else
    .Column(5, .ListCount - 1) = c.Offset(0, 5)
    'End If
    'Payment method
    .Column(6, .ListCount - 1) = c.Offset(0, 20)
    'Status
    .Column(7, .ListCount - 1) = c.Offset(0, 21)
    'row number of the record
    .Column(8, .ListCount - 1) = c.Row
    End With
    ' End If
    Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
    End With

    End With

    End Sub


    Now I would like that when I double click on a row of the listbox1, the selected record (8 columns) is populating the Listbox1 in the userform9
    No idea how to do it.
    thank you in advance.
    Giacomo
    Attached Images Attached Images

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Show only searched item in listbox only (userform)
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2017, 07:08 AM
  2. [SOLVED] Any Faster Way to Copy/Paste this range? (I have searched and searched and searched)
    By liquidmettle in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-12-2015, 02:33 PM
  3. make searched at combobox
    By bskaa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-30-2013, 09:13 AM
  4. Summary sheet that pulls specific data when searched for
    By Jake7208 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-24-2013, 01:59 AM
  5. Stopping VBA Search from showing error if searched item does not exist
    By viralshade in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-26-2013, 09:37 PM
  6. Replies: 2
    Last Post: 12-07-2012, 02:10 AM
  7. Replies: 6
    Last Post: 02-27-2010, 11:20 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1