+ Reply to Thread
Results 1 to 8 of 8

Set combobox number format

  1. #1
    Registered User
    Join Date
    10-08-2012
    Location
    NC
    MS-Off Ver
    Excel 2013
    Posts
    39

    Set combobox number format

    I'm pulling my hair out trying to figure out how to do one simple (??) thing. I have a combobox that is initialized when a form is opened with the following code:

    Please Login or Register  to view this content.
    This is used to select the time (in minutes) for scheduling. (I have another for choosing hour). The cells shown, B1:B60, are formatted to show two numbers so that minute 1 shows up as 01, 2 as 02 and so-on. But when these numbers are imported into the combobox list they display as 1, 2, 3, etc., instead of 01, 02, 03 and such. I have tried numerous different methods of number formatting to no avail. Some are shown below:

    Please Login or Register  to view this content.
    I assume it's something with the syntax? I haven't tried a piece of code I saw that assigns a format when values are brought in individually (I would have to change my import code). Can someone shed any light on what I'm doing wrong? Thanks!

  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: Set combobox number format

    So you want to populate the listbox with 01, 02, 03, 04... 59, 60?

    Or is it the specific values in the range B1:B60 formatted to 2 digits you want?

    This will do the former,
    Please Login or Register  to view this content.
    this will do the latter.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: Set combobox number format

    Ignore....

    @mikerickson - my answer was a 'shot in the dark' but as a working solution was posted at about the same time so I removed it.
    Last edited by grimes0332; 10-21-2016 at 06:04 PM.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Set combobox number format

    Grimes0332, the .Text property of a range does not return an array.

    One would have to loop

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    10-08-2012
    Location
    NC
    MS-Off Ver
    Excel 2013
    Posts
    39

    Re: Set combobox number format

    So you're basically importing it as a text entity, correct? I thought about doing that, but I use the numbers in a few equations. Will I need to convert them back to numbers (integers) before mathematical manipulation?

    I know this is a shift in the original question, but is there a simple way to invoke a *time only* clock, etc., from within VBA to select the time? This was my initial thought/plan, but all I could find was the time/date utility, and many people said it acted inconsistently based on the version of excel one used.
    Last edited by JonathanEngr; 10-21-2016 at 11:06 AM.

  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: Set combobox number format

    Did neither of my suggestions work?

  7. #7
    Registered User
    Join Date
    10-08-2012
    Location
    NC
    MS-Off Ver
    Excel 2013
    Posts
    39

    Re: Set combobox number format

    Norie--First of all, thank you for responding! I haven't had a chance to try them yet, but I did want to ask about the variable type since the weekend was approaching (trying to be proactive in case I got some type of error). I remember one time long ago having an issue with a number, and it's because it was being seen as text instead. It may not apply here, but I thought I would ask :-)

    I'll be sure and post back my results after editing my code. Thanks again!

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Set combobox number format

    The items in a ComboBox's list (or a ListBox's) are strings. Unlike cells, they don't have a format.

    The code has to be written to apply formats before putting the strints into those .Lists

+ 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. Need formula or code to convert number(s) from custom format to number format
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-12-2015, 07:44 PM
  2. Code for combobox to number format
    By moe1986 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-13-2014, 07:26 AM
  3. date Format in Combobox - format changes when data is transferred to database??
    By sgtbash999 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-08-2012, 06:13 PM
  4. [SOLVED] Decimal Number Format in ComboBox
    By Drummer361 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-06-2006, 05:25 PM
  5. Replies: 1
    Last Post: 05-18-2006, 11:45 PM
  6. [SOLVED] Number format for Combobox
    By MBlake in forum Excel General
    Replies: 1
    Last Post: 06-28-2005, 11:05 PM
  7. Number format based on number format of another cell in another workbook
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-09-2005, 01:06 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