+ Reply to Thread
Results 1 to 10 of 10

listbox column header macro

  1. #1
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Thumbs up listbox column header macro

    Hello friends,

    I have a code that helps me to open a list box from where i can choose items arranged in column A, sheet2.
    In column A, sheet2 i have: countries, cities, cars, fruits.
    In Sheet1 i have 2 buttons, when clicking <Let's go button>, a list box is open and i'm able to choose items that are inserted in column H, sheet1.

    Let's consider this items now are header columns, under Countries i have: UK, Albania, Egypt, Argentina, Canada, Mongolia, Tanzania.
    The challange is how can i add in column H, sheet1, one after another, if i want to select in listbox Countries and Cars columns, sheet2?

    Keeping in listbox just the header columns, when i choose one or more of them, after clicking OK button, on column H to get all items located under the selected header columns.

    Attached is an example, but it works only for Header columns, not for what is under each header column.

    Thank you
    Attached Files Attached Files
    Last edited by tuspilica; 02-23-2016 at 06:15 AM.

  2. #2
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53
    any directions or hints on this topic?

    thanks

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: listbox column header macro

    Hi tuspilica

    If I understand the issue, create Dynamic Named Ranges for Countries, Cities, Cars, Planets and Fruits.
    Then change your OK Button Code to this...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Re: listbox column header macro

    perfect my friend!!!
    it's exactly what i was looking for.

    many many thanks!

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: listbox column header macro

    You're welcome...glad I could help.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Re: listbox column header macro


    i tested the code, it's working perfect, but when i want to replace the name of the columns and run the macro, it fails.
    i'm realy confused, is there any hidden predefined list with the coulmn heads?

    Can you please take a minute to cast a look over this code again?
    The error line is this:
    Range(ListBox1.List(i)).Copy Sheet2.Range("H200").End(xlUp)(2, 1)

    How come the code knows that i changed the name of the column head?
    The data under the column head can be modified. in other words, i can not use it

    Thanks
    Last edited by tuspilica; 02-24-2016 at 05:19 PM.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: listbox column header macro

    Hi tuspilica

    Your Column Headers are in a Named Range and that Named Range is the Row Source for the UserForm ListBox1.

    If you've changed those Column Head Names you also need to change these Names to correspond to the Column Head Names.
    Dynamic Named Ranges for Countries, Cities, Cars, Planets and Fruits
    Understand? Yes? No?

  8. #8
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Re: listbox column header macro

    My friend,
    thank you. It's ok now.

    keep up the good work!

  9. #9
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Re: listbox column header macro

    My friend,
    thank you. It's ok now.

    keep up the good work!

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: listbox column header macro

    Hi tuspilica

    Good for you...you "see" the relationship. Seeing relationships is a major part of developing in VBA.

+ 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] Multi Column ListBox - set output formats for each column?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-10-2020, 10:27 AM
  2. Output data depended on Listbox selection
    By TPDave in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-15-2014, 09:31 AM
  3. Search Down Column, Activate Row from Columns A:X and Add Selection to Listbox
    By Zemillard in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-01-2014, 02:56 PM
  4. Hide Column Based on ListBox Selection
    By sarperb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2013, 03:38 PM
  5. Selection Results from userForm (Multiple-Column listBox)
    By bstubbs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2012, 06:01 PM
  6. 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
  7. ListBox selection output?
    By Freakazoid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2010, 02:12 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