+ Reply to Thread
Results 1 to 12 of 12

Another worksheet open corrupts userform listbox

  1. #1
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Another worksheet open corrupts userform listbox

    Hi,

    I have a userform with a listbox that displays columns of information based on a worksheet of that workbook. If I were to have the workbook open [WORKBOOK A] on the said worksheet and then open another workbook's sheet [WORKBOOK B] and then open the userform with the listbox from workbook A, the listbox is corrupted and pulls it's information from the columns of WORKBOOK B. Is there some way to tell the userform's listbox to only pull it's information from the correct worksheet and ignore other workbooks that may be open on the same time?

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551
    In your workbook that has your form use Thisworkbook.Range(whatever your range is)
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Re: Another worksheet open corrupts userform listbox

    Thanks Mike but it does not work. I am getting a compile error.

  4. #4
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Another worksheet open corrupts userform listbox

    You need to fully qualify whatever reference you are using to load the .List property of the ListBox.
    For example, if the list is populated from the Range A1:A6 in a sheet named "Sheet1" in myWorkbook then you need to reference like:
    Please Login or Register  to view this content.
    How are you populating the list?

  5. #5
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Re: Another worksheet open corrupts userform listbox

    Thanks cool blue but an error came up when I tried. I am populating the listbox currently with the below code:

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Another worksheet open corrupts userform listbox

    definitely you have something else wrong because you should be able to open multiple files and each of them to work fine
    Regards, John55
    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.

    ...enjoy -funny parrots-

  7. #7
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Another worksheet open corrupts userform listbox

    I didn't think that ListBox objects have a RowSource property.
    I think you need

    Please Login or Register  to view this content.
    But you should also include the workbook in the reference as per my first post.

    OOps, thats right, its on a form not the sheet...

    ? Sheet1.Range("A2:W1000").Address returns "$A$2:$W$1000" which is not very helpful.

    Please Login or Register  to view this content.
    Again, add the workbook name at the start.
    The easy way to do that is like this...
    Please Login or Register  to view this content.
    Last edited by coolblue; 08-17-2014 at 02:14 AM.

  8. #8
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Re: Another worksheet open corrupts userform listbox

    coolblue, thanks - this worked!

  9. #9
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Another worksheet open corrupts userform listbox

    Just be careful, its still not clear which Sheet1 you are referencing.
    The safe way is like this...
    Please Login or Register  to view this content.
    If it will always be the workbook that the UserForm is opened from then you can use ThisWorkbook as mentioned by @mike7952
    Please Login or Register  to view this content.
    Last edited by coolblue; 08-17-2014 at 02:47 AM.

  10. #10
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Re: Another worksheet open corrupts userform listbox

    Noted; thanks

  11. #11
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Re: Another worksheet open corrupts userform listbox

    Hi coolblue or anyone else, instead of starting a new thread I decided to reply to this. My problem was solved whereas my first listbox pulled its information from the correct worksheet without being corrupted and pulling information from another sheet which is open. However in my second listbox, I have a combobox [cboFilter] and a search button [cmdFilterSearch], where I can select an item in the box, click search and the listbox will be filtered to show the records containing the item searched for which is in column D. If I have another worksheet open and perform a filtered search, the listbox is blank because it is not finding the column D information it is supposed to find. My code is below. Can you help me point this code to my sheet1 which is called "Main"?

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Re: Another worksheet open corrupts userform listbox

    Please can someone help me with my above post? Thanks!

+ 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] Populating a UserForm ListBox with all Open workbooks
    By JoshExcel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-09-2014, 09:30 PM
  2. select a item in userform listbox to open a file
    By simeonmein in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2013, 09:36 AM
  3. Listbox to open worksheet
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-31-2012, 06:33 AM
  4. Excel 2007 : Excel Copy and Paste corrupts worksheet?
    By Marthe Lotz in forum Excel General
    Replies: 1
    Last Post: 09-06-2010, 10:35 AM
  5. Fill A Userform Listbox With Names OF All Open Workbooks
    By JR@SGC in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2007, 05:38 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