XL97: ActiveX Controls May Not Display Formatted Numeric Data

Last reviewed: March 13, 1998
Article ID: Q170442
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SYMPTOMS

TextBox, ComboBox, and ListBox controls do not display data in numeric Formats, for example:

  • If you have the date 1/1/97 in cell A1, and you set the LinkedCell property of a TextBox control to cell A1, the value 35431 appears in the TextBox. (This value is the serial value for the date 1/1/97.)
  • If you click an item in a ComboBox control that is a date, the ComboBox control displays the serial number for that date.
  • If you attach a click event macro to a ListBox control, and you click a date in the ListBox control, the value property of the ListBox control is the serial value for that date.

CAUSE

TextBox Control

If you create a TextBox control on a worksheet and you set the LinkedCell property to a cell with a number format, the number format is not used in the TextBox control.

ComboBox Control

If you create a Combo Box control on a worksheet or a UserForm, and you set the ListFillRange property (for a worksheet) or the RowSource property (for a UserForm) to a range of cells, the drop-down list uses the number format in that range, but the selected value does not.

ListBox Control

If you create a ListBox control on a UserForm, and you set the RowSource property of the ListBox control to a range of cells, the items in the ListBox control use the number formats in that range, but the value property of the ListBox control does not.

WORKAROUND

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

TextBox Control

To link a TextBox control to a worksheet cell, use a TextBox control from the Drawing toolbar instead of the Control Toolbox toolbar.

ComboBox Control

To use a ComboBox control containing a range of cells on a worksheet, use a ComboBox control from the Forms toolbar instead of the Control Toolbox toolbar.

If you are using a ComboBox control on a UserForm, use a macro for the Change event to set the Value property of the ComboBox control. The following example uses a ComboBox control and a macro for the Change event:

  1. Save and close all open workbooks, and then open a new workbook.

  2. On Sheet1, enter the following:

          A1: 1/1/97
          A2: 5/1/97
          A3: 10/10/97
    

  3. Start the Visual Basic Editor.

  4. On the Insert menu, click UserForm.

  5. Add a ComboBox control to the UserForm and set the RowSource property to Sheet1!A1:A3.

  6. Double-click the ComboBox control to display the Visual Basic module behind the UserForm, and then enter the following code for the Change event for the ComboBox:

          Private Sub ComboBox1_Change()
    

             ComboBox1.Value = Format(ComboBox1.Value, "m/d/yy")
    
          End Sub
    
    

  7. Run the UserForm and click the arrow on the ComboBox.

  8. Select any date in the list.

The selected date is displayed as the current value of the ComboBox control.

ListBox Control

If you have a ListBox control on either a UserForm or a worksheet, use a macro similar to the one for the ComboBox control to display the selected value for the ListBox control. For example, follow these steps:

  1. Save and close all open workbooks, and then open a new workbook.

  2. On Sheet1, enter the following:

          A1: 1/1/97
          A2: 5/1/97
          A3: 10/10/97
    

  3. Start the Visual Basic Editor.

  4. On the Insert menu, click UserForm.

  5. Add a List Box control to the UserForm and set the RowSource property to Sheet1!A1:A3.

  6. Double-click the ListBox control to display the module behind the UserForm, and enter the following code for the Click event for the ListBox control:

          Private Sub ListBox1_Click()
          
    
             x = Format(ListBox1.Value, "m/d/yy")
             MsgBox x
          
          End Sub
    
    

  7. Run the UserForm and click any date in the ListBox control.

The selected date is displayed in a message box.

STATUS

Microsoft has confirmed this to be a problem in Microsoft Excel 97 for Windows. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

REFERENCES

For more information about TextBox, ComboBox, and ListBox controls, click the Office Assistant, type "controls," click Search, and then click to view "Add buttons, check boxes, or other controls to a worksheet."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Excel Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120802
   TITLE     : Office: How to Add/Remove a Single Office
               Program or Component


Additional reference words: XL97
Keywords : kbcode kbprg kbtool xlvbainfo xldraw
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbbug
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.