+ Reply to Thread
Results 1 to 9 of 9

vba excel - formatting listbox values

  1. #1
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    vba excel - formatting listbox values

    This is driving me absolutely nuts. The code I use works perfectly for filling a userform listbox, even with other excel files open (even the macro file I'm trying to export into is open). I export the form and import it into my main project and now when I run it, I get an error 91: object variable or with block variable not set. All the variables are defined in a global list (just like my original form), it's the same identical code (just like my original form), and there is no other code running. I've isolated the problem to the formatting line. I'm at my wits end over something so stupid as a formatting issue? Is there an alternative code to what I'm trying to do? I can't understand why it would work in one document and not the other.
    Please Login or Register  to view this content.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: vba excel - formatting listbox values

    Hi,

    Try this:
    Please Login or Register  to view this content.
    As shown in:
    https://www.techonthenet.com/excel/f...mat_number.php
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - formatting listbox values

    I tried that. Still doesn't work. Works on the original form though.

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

    Re: vba excel - formatting listbox values

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - formatting listbox values

    Hi Norie. Thanks for taking a look at this. This is the actual file, not the original. I've noticed that another problem has arisen on form initialization, that being an invalid property array index. If you can solve the formatting bug, you will see what I'm talking about. The form will load a first time upon a workbook open. If I unload it and try and reopen it again, it gives me the 381 error. Something is lingering after closing the form.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - formatting listbox values

    One thing I notice about the invalid property array index error is if I unload the form (via X or the cmd), and try to initialize the form again, the error occurs. If I click the reset button after the error occurs, the form initializes. What's up with that? Does not unloading the form unload it from memory, or is there some sort of loop that I've inadvertently created that runs even when the form is unloaded?

    EDIT: Since this is a new problem unrelated, I've posted another topic pertaining to this particular problem.
    https://www.excelforum.com/excel-pro...ml#post4764366
    Last edited by terriertrip; 10-17-2017 at 01:47 AM.

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: vba excel - formatting listbox values

    Hi,

    The lack of capitalisation of Val is a clue- you have defined a Range variable called val which is interfering. Rename it.

    Also, you really need to get out of the habit of public variables for everything- a variable should have the narrowest scope possible and should only be made Public when there is no other practical option.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  8. #8
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - formatting listbox values

    Thank you for your guidance xlnitwit. I have many forms in this project, so my working assumption was that it was a shortcut since I was using the same variables in much of the code - but by all accounts all it does is create more potential issues. I see that now. I will educate myself a little more on the use of Public vs. Private declaration.

  9. #9
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - formatting listbox values

    Thank you all for your help. Taking xlnitwit's suggest has fixed the issues. I'll chalk it up as another hard lesson.

+ 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. Formatting values in listbox to show currency
    By chrisellis250 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2017, 11:39 AM
  2. Show dynamic values at listbox depending value selected another listbox
    By Judith_Chao in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2017, 08:30 AM
  3. insert listbox values into excel
    By shiftyspina in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2015, 10:30 AM
  4. [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
  5. Based on listbox values, go to a URL in webbrowser containing those listbox values
    By krisspy in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-08-2014, 02:05 PM
  6. [SOLVED] excel vba filter values to listbox from combobox and save edit values in textbox
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2013, 08:42 AM
  7. loop through values in listbox and search for them in excel sheet
    By longhorn23 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-29-2010, 08:32 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