+ Reply to Thread
Results 1 to 5 of 5

Building a list for Active X Listbox

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Building a list for Active X Listbox

    In the attached there is a listbox in the vicinity of Cell D1 on the pivot sheet. I woulds like to populate it with the contents of Lookups!A2:A6. I realize I can do this without VBA, however, when I copy the sheet to a new workbook, the source data links back to the old workbook (the one that is posted here). If this workbook isn't available and open then the listbox is blank.

    I need to populate it with "hard" values so it doesn't reference back to a workbook that won't be available to the end user. I think VBA is the only solution for this. If there is the equivalent of break link and use values I'll take that solution. If there is a way to assign the range to display to the local table instead of the one in the generating workbook, I'll take that too.

    Here is my code:
    Please Login or Register  to view this content.
    I get the error Compile Error: Method or data member not found on:
    shtP.ListBox1.AddItem "FOO"
    It specifically higlights ListBox1

    However this is the syntax all the articles I've found so far are using.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Building a list for Active X Listbox

    it likes this code better - i cannot see why - put it down Bill Gates.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Building a list for Active X Listbox

    Hi there,

    I think that life becomes a bit simpler when you work from the VBA CodeModule of the "Pivot" worksheet itself (rather than a standard VBA CodeModule), so see if the following code (entered in that CodeModule) does what you need:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Building a list for Active X Listbox

    Hi again,

    If you want to stick with your original approach, it seems you have to use the following code:

    Please Login or Register  to view this content.

    Hope this helps.

    Regards,

    Greg M

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Building a list for Active X Listbox

    I found the root cause: If you already have the box populated with a range, it will fail. Remove the range and it works as all the other articles said it should.

    Also I changed my plan of attack: instead of creating a workbook and adding only the pages I needed for the report, I made a copy of the workbook that generated everything, copy / pastespecial values only for some formulas (mostly lookups from pages that I didn't need copied) and removed the sheets I didn't need, hid the "background" pages and saved the copy.

    Thanks everyone for chiming in. I've worked with listboxes in forms before, buy active X controls on the sheets is relatively new to me.

+ 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] Editable Active X Textbox Linked to Active X List Box
    By bowater in forum Excel General
    Replies: 1
    Last Post: 12-08-2016, 07:44 PM
  2. Active X listbox
    By compgeek1979 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2015, 11:05 AM
  3. [SOLVED] How do I populate a listbox with a list excluding values found in another listbox?
    By Hokiefan00 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-27-2014, 01:47 PM
  4. [SOLVED] How can I active a row from a listbox in a user form?
    By Magma310 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-07-2013, 03:42 PM
  5. [SOLVED] Active X ListBox Fill Range
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-05-2012, 12:12 PM
  6. Replies: 2
    Last Post: 10-08-2012, 12:49 PM
  7. problem about building a listbox from another list
    By liangxin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2005, 09:28 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