+ Reply to Thread
Results 1 to 20 of 20

Can't delete names that are all numbers in userform listbox.

  1. #1
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Can't delete names that are all numbers in userform listbox.

    Hello all! In this macro I can't delete names that are all numbers via the userform. I can delete names that are mixes of letters and numbers just not all numbers (e.g 123123123). Any help on fixing this would be greatly appreciated! I am attaching the file for convenience.

    The error in debug pinpoints the line that i am underlining in the following code.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Can't delete names that are all numbers in userform listbox.

    When you enter numbers in Excel, Excel assumes that those are, in fact, numbers. When you load a combobox with numbers, the combobox doesn't care what it is and inserts it as a string. When you assign the combobox to a variable, then use that in the match function, it is passed a string and thus can't find the number in the column.

    Use
    Please Login or Register  to view this content.
    Or, you can enter the numbers with a tick mark in front to tell Excel that this is text.

    There are a few more ways to handle this if you can't get it working.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Re: Can't delete names that are all numbers in userform listbox.

    Tinbendr, I added the line but now whenever I try to delete something I get an error on and it wont delete from the listbox.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Can't delete names that are all numbers in userform listbox.

    Did you add the Val?

    Works on my copy.

  5. #5
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Re: Can't delete names that are all numbers in userform listbox.

    Yes, I deleted mine and added yours. I actually tried a non numerical name first, since it didn't work I didn't try to do a all numerical name.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Can't delete names that are all numbers in userform listbox.

    Declare k as Variant.

    By the way, why are you looping if the listbox isn't multiselect?

    For a single select listbox all you need to delete the selected item is the ListIndex.
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Re: Can't delete names that are all numbers in userform listbox.

    Either I found an example that handled it that way or someone helped me with that part and did it that way. I am very new to the language so I am grasping these concepts as I go.

    I added the line

    Please Login or Register  to view this content.
    I have the same error but the error moved to this line

    Please Login or Register  to view this content.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Can't delete names that are all numbers in userform listbox.

    Did you also use Tinbendr suggestion of Val?

    If you still can't get it to work with that here's a version using ListIndex.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Can't delete names that are all numbers in userform listbox.

    Norie's right, you don't have to use a loop when Multi-Select is off.

    Here's a version with the iteration. Just in case you ever change you mind and turn multiselect on.

    Please Login or Register  to view this content.
    Last edited by Tinbendr; 07-18-2014 at 09:58 AM.

  10. #10
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Re: Can't delete names that are all numbers in userform listbox.

    GREAT! That did it :D Thank you Norie. Nice improvement!

  11. #11
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Re: Can't delete names that are all numbers in userform listbox.

    I can't add to your reputation because I think you where the last person that I added to!

  12. #12
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Re: Can't delete names that are all numbers in userform listbox.

    Thank you both, appreciate it! Btw, how do I select more than one choice in the listbox. I am trying but no go.

    Edit

    I went to properties and looked at the multiselect option. There are 3 options, 0, 1 and 2 what is difference between 1 and 2?

    Edit 2

    I changed multiselect to 1 and then 2 and in both instances whenever I try to delete two it only deletes the option which is lower down the list.
    Last edited by Inti; 07-18-2014 at 10:42 AM.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Can't delete names that are all numbers in userform listbox.

    Inti

    Since you repopulate the listbox after you've deleted you could miss out bit that deletes from the listbox.

  14. #14
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Re: Can't delete names that are all numbers in userform listbox.

    Yes it's being repopulated to make sure that the items in the listbox are the latest ones found in the site list spreadsheet. Why is it only deleted the last item in the selection?

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Can't delete names that are all numbers in userform listbox.

    Which code are you using?

    Have you tried getting rid of this?
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Re: Can't delete names that are all numbers in userform listbox.

    I used yours initially but once Tinbendr suggested his script I added it. It works fine no errors but behaves as described this is the code for the delete tab

    Please Login or Register  to view this content.

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Can't delete names that are all numbers in userform listbox.

    Have you tried removing this?
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Re: Can't delete names that are all numbers in userform listbox.

    Do you mean a specific line or all of the instances where that line appears?

  19. #19
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Can't delete names that are all numbers in userform listbox.

    All the instances in that sub.

    Like I said you don't need to delete the items from the listbox as you end up repopulating it from the worksheet anyway.

  20. #20
    Registered User
    Join Date
    06-18-2014
    Location
    Houston, TX
    MS-Off Ver
    2010
    Posts
    63

    Re: Can't delete names that are all numbers in userform listbox.

    Your code works great to delete 1 selection. I am trying the multi-selection code that Tin provided and on that one I deleted the instances of that line but it is still not deleting the rows or the items on the listbox.

    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. Userform Delete from Listbox and cell
    By jasonmcbee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-26-2014, 09:45 PM
  2. [SOLVED] Can add listbox control to userform, but cannot delete!
    By perducci in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2013, 02:03 PM
  3. Delete record from listbox via Userform
    By Jonathan78 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-19-2011, 03:31 AM
  4. UserForm freezes after delete from Listbox
    By NewExcelVBA in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-28-2011, 02:34 PM
  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