+ Reply to Thread
Results 1 to 9 of 9

getting type mismatch using list listindex

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    getting type mismatch using list listindex

    this used to work, but i must have done something to make it stop. not sure what it is.

    when i run the button on the addvendor sheet and type in the search box, all appears to be fine. but when i pick the item in the listbox, i get a type mismatch 13, run time error on this line:

    Please Login or Register  to view this content.
    when i type this in the immediate window, i get the same error: ?sht.Cells(.List(.ListIndex, 1), 4)

    i checked the sht.name and it is correct. i checked the activesheet.name and it is correct.

    what did i do wrong in the code to make this stop working?
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,802

    Re: getting type mismatch using list listindex

    I don't know how this used to work. Your listbox has 1 column, but your formula is referring to the second column. Column indexing for a listbox is 0-based, so column 0 is the first column and column 1 is the second column. The reference to

    .List(.ListIndex, 1)

    is returning Null. If you are trying to get the item selected as displayed in the listbox, you can omit the column reference.

    Please Login or Register  to view this content.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: getting type mismatch using list listindex

    6stringjazzer, thanks for replying.

    tried the following, both do not work and gives me the same error on the same line (see image):
    Please Login or Register  to view this content.
    i have to be doing something wrong i think

    Attachment 654140

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,802

    Re: getting type mismatch using list listindex

    OK, I have to do a little mind reading here. I think what you intended to do is to use the second column of the listbox to store the row number of the selected item where it appears on sheet VendorInfo. But the listbox only has one column, and that info is never stored.

    I updated the properties of your listbox to have 2 columns, and made this update to your Search Sub:
    Please Login or Register  to view this content.
    And it seems to work but it's hard to check because I cannot figure how your tb_* variables are defined.
    Then I get a type mismatch error at
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    The ListIndex value is 0 and so the array index is 1 but I can't figure out how arr is assigned values so I got stuck here. I did not want to sink more time into diagnosis at this point until you can explain how arr is being used.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,802

    Re: getting type mismatch using list listindex

    Your attachment in post #3 did not work. I am guessing you tried to attach an image. I think there is a bug in picture attachments. Try going into Preview mode before you attach the image.

  6. #6
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: getting type mismatch using list listindex

    weird, i can get the PNG to open up when i click the link, maybe i'll use a jpg instead in the future and see if that works. so not sure about the multiple columns showing the row number, not the way that i intended it to work. let me elaborate. The VendorInfo is all the information about my vendor, address, phone, contact, etc. my multiple use userform1 allows many things to be done. the most important is to search the data based on search term (tb_search) and return all items to the listbox. what is returned is the vendor name and a dash, and then the vendor number. this all goes in the listbox. when i select ONE item in the listbox, i want it to return all the information found and put that in the tb_*** textboxes. how can that be done.

    as for "arr", its supposed to find the row number of the selected item, how can that be done correctly? again, not sure what i did to make this stop working but one of the forum members helped me out with the code.

    Thanks for all of your help.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,802

    Re: getting type mismatch using list listindex

    The fact that arr is declared globally in one place and locally in another place and used for different things make this code very confusing to follow. The only place you are assigning values to the global version is in CommandButton4_Click_old which appears to be obsolete. And so when ListBox1_Click references it, it causes an error. Since you are after the row number here, I will use the row number that was stored in the list in my previous update.

    My general sense is that the overall design is more complex than necessary but I'll just focus on getting it to work. Please try this out and let me know if it works the way you want.

  8. #8
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: getting type mismatch using list listindex

    yes 6stringJazzer, that works like a charm. was able to set the column widths and move the row offscreen. had to recode the total matches so that it matched the listcount. so everything is working great. many thanks for fixing this for me, i truly appreciate it.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,802

    Re: getting type mismatch using list listindex

    Glad to help, thanks for the rep!

+ 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] Get additional matching selection from combo box .List(ListIndex)
    By jprlimey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2017, 07:00 PM
  2. Run Type error 13 Type Mismatch
    By Affan Khan in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-13-2012, 12:58 PM
  3. [SOLVED] Iterate Through Names, list unused: Type Mismatch with Cells.Find
    By tlafferty in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2012, 04:03 PM
  4. [SOLVED] Run-type error 13 type mismatch
    By misop in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-05-2012, 04:08 AM
  5. Type Mismatch: array or user defined type expected
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2006, 10:45 AM
  6. [SOLVED] Type mismatch using rnge as Range with Type 8 Input Box
    By STEVE BELL in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-03-2005, 01:10 AM
  7. Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 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