+ Reply to Thread
Results 1 to 15 of 15

VBA userform list box to show visible result only from a filtered table

  1. #1
    Registered User
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    87

    VBA userform list box to show visible result only from a filtered table

    Hi,

    I am trying to build a user form with a list box that shows a filtered result of a table. Currently, my code only shows the full table as obviously, the code ignores that my table is filtered and shows me the full table content. Could anyone please point me in the right direction of showing only the visible result in the grid? Thank you!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: VBA userform list box to show visible result only from a filtered table

    Try:
    Please Login or Register  to view this content.
    Instead of:
    Please Login or Register  to view this content.

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

    Re: VBA userform list box to show visible result only from a filtered table

    Would be easier with a sample upload...see top yellow banner...
    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!!!

  4. #4
    Registered User
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    87

    Re: VBA userform list box to show visible result only from a filtered table

    Hi CheeseSandwich, now the list box only shows the header row and nothing else......

  5. #5
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: VBA userform list box to show visible result only from a filtered table

    What was visible in your filtered data at that point?

    Are your headers in row 3? If so then Maybe:
    Please Login or Register  to view this content.
    Also as @Sintek stated, we could do with a file to work on - you have mentioned you are using a table, the way to define the range of a table is different from the way you work with ranges - we could have a look if we had a dummy file.

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

    Re: VBA userform list box to show visible result only from a filtered table

    Listbox cannot be populated that way if non contiguous data...
    Are a few other options available...
    Upload sample file as suggested if you would like a result...

  7. #7
    Registered User
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    87

    Re: VBA userform list box to show visible result only from a filtered table

    Hi ChesseSanwich and Sintek, I will try to make a dummy file now as the current one has 33 sheets and contains real customer data so I will make a fresh dummy file. And by the way. the below code

    Please Login or Register  to view this content.
    only shows the first line of the filtered table

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

    Re: VBA userform list box to show visible result only from a filtered table

    That won't work...It is also advisable to keep the control names as default...especially when you start developing bigger interfaces...makes for easier looping population...

  9. #9
    Registered User
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    87

    Re: VBA userform list box to show visible result only from a filtered table

    Thanks sintek, thanks for the advice. The development did get bigger and it looks very messy now with 33 sheets 46 modules and 20 user forms as I didn't do much structure planning and put a lot of ad-hoc features on as I go along. I will try to tidy the project up. (Big task)

    I was wondering, is there a way I can just copy the filtered table result to another sheet like a helper sheet then use the list box to show that as result?

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

    Re: VBA userform list box to show visible result only from a filtered table

    This will give you an idea...if your data is an actual Table and not a range...
    Please Login or Register  to view this content.
    I was wondering, is there a way I can just copy the filtered table result to another sheet like a helper sheet then use the list box to show that as result?
    Yes that is an option...Not ideal though...Your way wanting to copy to another sheet?
    Please Login or Register  to view this content.
    Or another Option....
    Please Login or Register  to view this content.
    Last edited by sintek; 03-21-2022 at 07:40 AM.

  11. #11
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: VBA userform list box to show visible result only from a filtered table

    Yes my bad on that one - forgot about the contiguous piece.

    The attached is displaying only visible items from the table - you may be able to mimic this.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    87

    Re: VBA userform list box to show visible result only from a filtered table

    Thank you both for such wonderful solutions. I have used ChesseSandwich's code and this works perfect!!!!

  13. #13
    Registered User
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    87

    Re: VBA userform list box to show visible result only from a filtered table

    Quote Originally Posted by CheeseSandwich View Post
    Yes my bad on that one - forgot about the contiguous piece.

    The attached is displaying only visible items from the table - you may be able to mimic this.
    Hey CheeseSandwich, if after the filter is applied it has no result, it will give a 1004 error. I am trying to add error handling above your code to go to skip: but the error still pops up. Where should I add the error handling if no result after filtered is encountered? Thanks!

  14. #14
    Registered User
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    87

    Re: VBA userform list box to show visible result only from a filtered table

    Hi I think I can just check to see if the table is not empty before deployment of your code by something like If TargetTable.DataBodyRange.VisibleRows.Count > 0

  15. #15
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: VBA userform list box to show visible result only from a filtered table

    I have added some error handling around where it sets the table range 'filtRng', if the table is hidden entirely then this line will error. We can catch that error and return a message box then exit the sub.
    Please Login or Register  to view this content.

+ 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. [SOLVED] Selecting the first x visible rows of a filtered table
    By DreamEyes in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-27-2017, 11:05 AM
  2. Moving to next visible row in filtered list
    By nielsskovjoergensen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2017, 02:44 PM
  3. [SOLVED] How to filter a table using textbox and show filtered data in listbox (userform)
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-01-2017, 10:31 AM
  4. Copy visible cells in filtered table and paste in userform textbox - email
    By pfeifferjoey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-29-2014, 11:23 AM
  5. Replies: 1
    Last Post: 03-16-2014, 08:52 PM
  6. Selecting 2nd to last Visible row in a filtered list
    By PSBuskey in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-11-2013, 04:43 PM
  7. How to sum a filtered list by visible cells only?
    By DorothyFan1 in forum Excel General
    Replies: 2
    Last Post: 10-10-2011, 02:03 PM

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