+ Reply to Thread
Results 1 to 14 of 14

Listbox auto fit column width

  1. #1
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Listbox auto fit column width

    Hi

    I just want to know how to Autofit Column width of Listbox.

    Please help!!!

    Thanks
    Thiru

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Listbox auto fit column width

    This seems to get it pretty close:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: Listbox auto fit column width

    But the list box is in Userform - how to do that? - Please Help

    Thanks
    Thiru

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Listbox auto fit column width

    If its name is still "ListBox1" the code should still apply - but, is it the same width as the userform - if so, then maybe you should use "UserForm1" instead??

  5. #5
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: Listbox auto fit column width

    Getting Error Msg

    This is the code that I have
    Please Login or Register  to view this content.
    Dim S As Single
    S = UserForm1.OLEObjects("ListBox1").Width / 6
    Columns("D:D").ColumnWidth = S * 1.077

  6. #6
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: Listbox auto fit column width

    Even I change the code - it doesn't work.
    Please Login or Register  to view this content.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Listbox auto fit column width

    Can you post a sample spreadsheet with your userform including the listbox?

  8. #8
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: Listbox auto fit column width

    Please find the attached.

    Thanks
    Thiru
    Attached Files Attached Files
    Last edited by sthiru; 06-20-2013 at 02:39 PM.

  9. #9
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: Listbox auto fit column width

    Quote Originally Posted by xladept View Post
    Can you post a sample spreadsheet with your userform including the listbox?
    Any update sir?

    Thanks
    Thiru

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Listbox auto fit column width

    Hi SThiru,

    Your program trashed my system the first time I brought it up but subsequently I discovered that the list box width was 585.95 or something like that - when I ran my program on it it seemed to work - but I'm not sure now what you wanted.

    BTW - I posted this response, or a similar one yesterday - I have no idea why it didn't take

  11. #11
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: Listbox auto fit column width

    Its ok! I have found the solution - Below is the code for the people who searching for this.

    Please Login or Register  to view this content.
    Last edited by sthiru; 06-24-2013 at 08:21 PM. Reason: Additional Information

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Listbox auto fit column width

    Glad you got it!

  13. #13
    Registered User
    Join Date
    05-22-2011
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: Listbox auto fit column width

    Quote Originally Posted by xladept View Post
    Glad you got it!
    Thank you xladept ;-)

  14. #14
    Registered User
    Join Date
    04-10-2020
    Location
    greece
    MS-Off Ver
    2016
    Posts
    2

    Re: Listbox auto fit column width

    Autosize list/combobox columns with this function. Optionaly autosize the list/combobox itself.

    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)

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