+ Reply to Thread
Results 1 to 10 of 10

Add items in listbox based on 2 criteria

  1. #1
    Forum Contributor
    Join Date
    10-10-2012
    Location
    Mumbai,India
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    104

    Add items in listbox based on 2 criteria

    Respected Members,
    I wish to add data to two different Listboxes from Sheet1 based on two criteria ie. Column B and Column CV
    If column CV contains "sales" then add items to SALESLB if it contains "Income" then add items to PAYMENTRECEIVEDLB
    I am able to get data in SALESLB but cannot achieve the same for income part. I have attached the sample file with code in it
    Need to know where I am going wrong ; Any Inputs is highly appreciated
    Thanks and regards !
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,248

    Re: Add items in listbox based on 2 criteria

    To examine anything in the attached file you need a sheet with the code name "Sheet4". The "receivable" control is missing from the Userform.

    Artik

  3. #3
    Forum Contributor
    Join Date
    10-10-2012
    Location
    Mumbai,India
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    104

    Re: Add items in listbox based on 2 criteria

    My Bad , here is the updated workbook
    Attached Files Attached Files

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Add items in listbox based on 2 criteria

    Which columns must appear in listbox...as per your code....3,4,6,7 and other 101,102,103,104,105
    And it seems you want this to happen when you select a client from the combobox...Is this correct
    Last edited by sintek; 04-19-2024 at 06:49 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Forum Contributor
    Join Date
    10-10-2012
    Location
    Mumbai,India
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    104

    Re: Add items in listbox based on 2 criteria

    @sintek yes sir ! Criteria being in Column CV

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Add items in listbox based on 2 criteria

    One way...Have changed your approach...Assumes that Column always has either sales or income entries
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sintek; 04-19-2024 at 07:20 AM.

  7. #7
    Forum Contributor
    Join Date
    10-10-2012
    Location
    Mumbai,India
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    104

    Re: Add items in listbox based on 2 criteria

    I tried implementing your method it works out fine with few issues
    1. It doesn't add up income values (probably due to number being stored as text error)
    2. If no entries are present for a selected client the column headers are listed down in listbox. for eg. if you search for entries of "Jack" The column headers are listed down in sales list box
    3. Sheets("SalesDB").Cells(1).CurrentRegion " this method of selecting data in my humble opinion is not much reliable as ; if few cells are left empty the desired range may not get selected . could you help me with other way to select the range of data please.
    I have attached the sample workbook for reference.
    Attached Files Attached Files

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Add items in listbox based on 2 criteria

    It doesn't add up income values (probably due to number being stored as text error)
    So...Enter your numbers as numbers not text...
    If no entries are present for a selected client the column headers are listed down in listbox. for eg. if you search for entries of "Jack" The column headers are listed down in sales list box
    Has been resolved...
    Sheets("SalesDB").Cells(1).CurrentRegion " this method of selecting data in my humble opinion is not much reliable as ; if few cells are left empty the desired range may not get selected
    If you design your sheet and layout your data properly i.e. No blank columns and blank rows in data...this works very well...Has been resolved for this file...
    Attached Files Attached Files
    Last edited by sintek; 04-20-2024 at 03:21 AM.

  9. #9
    Forum Contributor
    Join Date
    10-10-2012
    Location
    Mumbai,India
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    104

    Re: Add items in listbox based on 2 criteria

    Quote Originally Posted by sintek View Post
    So...Enter your numbers as numbers not text...
    Could 'you suggest me how to do it . As the numbers automatically gets converted to text when saving from userform ! I have to manually convert to number each time
    Went through the workbook again rest everything seems fine ! Will give it a thorough check before marking this thread as Solved !

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Add items in listbox based on 2 criteria

    As the numbers automatically gets converted to text when saving from userform
    Cannot see your Userform code...I'm guessing though you must add..as example

    Please Login or Register  to view this content.
    to the code...
    Can only ascertain once code is provided...
    Last edited by sintek; 04-20-2024 at 09:59 AM.

+ 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. Listbox select items based on another listbox
    By Undo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2022, 07:49 AM
  2. [SOLVED] populate listbox with unique items based on criteria in column C
    By bqheng in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-23-2017, 06:55 PM
  3. Use Selected Items from ListBox As Filter Criteria, Including Blanks
    By FallingDown in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2015, 06:13 AM
  4. [SOLVED] Use Selected Items from ListBox As Filter Criteria
    By FallingDown in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2015, 12:13 PM
  5. Transfer random listbox items to new listbox and then loop through selected items
    By narrowgate88 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2013, 05:58 PM
  6. Macro for listbox items to be added as per criteria
    By amolryeolekar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-20-2013, 11:57 AM
  7. Multi select Listbox Items selection based on other Listbox item selection.
    By srinivassathi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2011, 05:53 AM

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