+ Reply to Thread
Results 1 to 10 of 10

Multi Column ListBox - set output formats for each column?

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Multi Column ListBox - set output formats for each column?

    I am using a custom built 2D variant array to populate a ListBox on a user form.
    One of the columns in the array stores Boolean data.
    However when I output the array to the InputBox, the boolean column data displays as -1.

    How do I set the format of the Boolean array column to show as TRUE/FALSE in the ListBox that is created?

    (On a minor related note, I have a column of integers which I want to display as currency $##,###. How do I do this?)
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

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

    Re: Multi Column ListBox - set output formats for each column?

    How are you currently displaying the values?

    For numeric formatting, eg currency, you might want to look at is the Format function.
    If posting code please use code tags, see here.

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Multi Column ListBox - set output formats for each column?

    Quote Originally Posted by Norie View Post
    How are you currently displaying the values?
    I don't quite understand. (Please have patience on a newbie!) I have a 2D variant array which populates the listbox. I assume the formatting is auto assigned somehow?

    Currently the 1st & 2nd columns display as strings (which is fine - they are individuals names).
    The 3rd column displays as currency (also fine - I only asked the 2nd question in the 1st post so I would know what to do if I did encounter this issue)
    The 4th column displays in the listbox as -1 values (which is not fine - it is a boolean array of TRUE/FALSE. I understand that -1 = FALSE but I want to display the word FALSE in this column for the end users benefit).

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Multi Column ListBox - set output formats for each column?

    Hello mc84excel,

    Boolean values are stored as numbers. The words TRUE and FALSE are formatting options applied to the worksheet cells. Internally the values are still numbers. A Boolean false is False is universally a 0 (zero). A True in VBA is a -1 (negative one) by default but VBA recognizes any non zero value as True in a Boolean test.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Multi Column ListBox - set output formats for each column?

    Quote Originally Posted by Leith Ross View Post
    Hello mc84excel,

    Boolean values are stored as numbers. The words TRUE and FALSE are formatting options applied to the worksheet cells. Internally the values are still numbers. A Boolean false is False is universally a 0 (zero). A True in VBA is a -1 (negative one) by default but VBA recognizes any non zero value as True in a Boolean test.
    Yes you are right re 0 and -1 (I had it the wrong way round )

    I am puzzled though. If I go to local window and check the array, it displays the values as TRUE & FALSE. It is only when the array is populating the ListBox that I get the values appear as -1 and 0.

    So to solve my question - do you know how I can alter the display format of the 4th column in a listbox?

  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: Multi Column ListBox - set output formats for each column?

    How are you populating the combobox from the array?

    Are you using List or are you looping through the array and using AddItem?

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Multi Column ListBox - set output formats for each column?

    Quote Originally Posted by Norie View Post
    How are you populating the combobox from the array?

    Are you using List or are you looping through the array and using AddItem?
    By .List.

    So how do I assign the formats for each column in the ListBox?
    Last edited by mc84excel; 05-28-2013 at 10:50 PM. Reason: clarify

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Multi Column ListBox - set output formats for each column?

    So is it impossible to set each column of the combo box to a different format?

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Multi Column ListBox - set output formats for each column?

    Marking this thread as solved as I consider it impossible. The listbox displays in the format that is passed to it. This can be bypassed by looping through your array and altering the formats before passing to your listbox/combobox (e.g. I do this on an array of integers - I convert them to currency format before passing to listbox)

  10. #10
    Registered User
    Join Date
    09-30-2020
    Location
    Luxembourg
    MS-Off Ver
    2019
    Posts
    1

    Re: Multi Column ListBox - set output formats for each column?

    Hello all,

    Try to use instead of cells(x,y).value pass cells(x,y).text and it will assume the formatting that you have in the sheets.

    I hope i was helpful

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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