+ Reply to Thread
Results 1 to 2 of 2

Excel & VB - Setting the minimum width of a ComboBox & AutoSize

  1. #1
    Registered User
    Join Date
    03-26-2013
    Location
    WI
    MS-Off Ver
    Excel 2010
    Posts
    6

    Excel & VB - Setting the minimum width of a ComboBox & AutoSize

    Hello,

    I was wondering if this is possible to do or not. I am pretty sure it’s not, but wanted to see if it was and someone else might know how. I am using Excel 2010 and everything is being done with VBA. What I would like to do is set a ComboBox with a minimum width size and then AutoSize if typed data becomes longer than the length of the ComboBox.

    OK, so let me clarify some misconceptions or questions that I am going to get asked about, such as why I would want to allow users to type in a ComboBox. On another sheet, apart from the sheet that the ComboBox is on, I have a list of items. As items are typed in here the ComboBox is populated with the new item, I also have it sorting the list in alphabetical order and it spell checks them too, as they are being added.

    I then have the code to also check for the longest length of text in each cell and the ComboBox will size to the longest length of text within its list, so it can fully be read in the dropdown.

    I also want users to be able to type in the ComboBox for items that are not in the list already. The list is for just the most common items used, but often other miscellaneous stuff needs to be entered. I don’t want the miscellaneous stuff added to the list within the ComboBox, so I just want the user to be able to type in data within the ComboBox, but if it is used a lot they can add it to the list on the other sheet.

    In case someone is wondering, I do have spellcheck working for the ComboBox when users type data in. All I did was make the cell that the ComboBox is over equal to the text in the ComboBox when the ComboBox is deactivated (LostFocus), then I spellcheck that cell, followed by making the ComboBox equal to the cell that was just spellchecked.

    Anyway, as already mentioned I do have the ComboBox’s width set to the longest item in the list using code. Is there a way that I can somehow keep the ComboBox’s minimum width set to this size, but then the width will increase when the user is typing data in that becomes longer than what the box is currently set to? I am guessing this would be easy to do if I was to adjust it after the user finished typing (when the ComboBox LostFocus), but is it possible to do this while they are typing? Setting the AutoSize will not work, because it will ignore the size of the longest item in the list, and shrink to almost nothing, making it impossible to see the items in the list.

    Thanks for any suggestions,

    Zines
    Last edited by zines; 11-25-2013 at 12:18 AM.

  2. #2
    Registered User
    Join Date
    03-26-2013
    Location
    WI
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Excel & VB - Setting the minimum width of a ComboBox & AutoSize

    I guess it is possible to do, I just figured it out. The iLength is what determines the default minimum width size should be, which is slightly larger than the size of a column in a different sheet where the ComboBox is pulling its data from. I just did some basic calculations to figure that the length (character count) of text being typed in the notes field is about 4.5 times smaller than the default length. Of course, the 4.5 would change if I used a different sized font. If the typed text (based on the calculation) becomes greater than the default size, I set the ComboBox to AutoSize, otherwise AutoSize was set to False. Then when I cleared the data from the field I just have the code in the clear button to reset the ComboBox back to the default size and to set AutoSize to False. This works perfectly.

    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. Setting Column Width In Every Excel Table Embeded In Word
    By mgaworecki in forum Word Programming / VBA / Macros
    Replies: 10
    Last Post: 10-12-2011, 09:34 AM
  2. ComboBox Autosize Font
    By yawnzzzz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-08-2011, 08:39 AM
  3. [SOLVED] Setting Column width & Row height in excel 2003
    By prasadsn1976 in forum Excel General
    Replies: 1
    Last Post: 03-01-2011, 05:30 PM
  4. ComboBox autosize
    By GIP in forum Excel General
    Replies: 3
    Last Post: 08-22-2010, 01:42 PM
  5. Replies: 1
    Last Post: 10-28-2009, 05:02 AM

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