Consulting

Results 1 to 17 of 17

Thread: Format display in the comboBox

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    10
    Location

    Exclamation Format display in the comboBox

    Dear all,

    Would anyone help me solve my problem- the Datevalue display in the comboBox will change to the format of string when I selected. How can I fix it when I selected the date and display the same.
    Please refer to my attached file and press the Data Entry (Command Button).

    Thanks,
    Apen

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Could it be possible to get the string value selected to drop into a list (a range on another sheet first), then have this range formatted to the date format you require? The combo box could then pick up this range as its source.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    apen

    How can we possibly help you?

    The code in the workbook you posted is password protected and constantly errors anyway.

  4. #4
    VBAX Regular
    Joined
    May 2008
    Posts
    10
    Location
    Dear Aussiebear,

    If I put the value in form of string, the data inputting to the wokrsheets( " Attendance " and could not calculate, so would you suggest another way.

    apen

  5. #5
    VBAX Regular
    Joined
    May 2008
    Posts
    10
    Location
    I am sorry for that, let me try to post any thread with no password., but anyway it is not related to password because the comboBox's value is refer to the data list in worksheet("Select")

    The VBA is:

    Userform2.comboBox1.RowSource =Sheets("Select")!Name

    Apen

  6. #6
    VBAX Regular
    Joined
    May 2008
    Posts
    10
    Location
    I have re-attached the file without password.

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Private Sub ComboBox2_Click()
    Dim ra As Variant
    ra = ComboBox2.Value
    Application.ScreenUpdating = True
    ComboBox2 = Format(ComboBox2, "dd-mmm-yy")
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    VBAX Regular
    Joined
    May 2008
    Posts
    10
    Location
    Dear Mdamackillop,

    the code still having an error on the " Format"

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Check for missing VBA references. Tools/References. Uncheck any that are marked Missing
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    [vba]ComboBox2 = Format(ComboBox2, "dd-mmm-yy") [/vba]

    As a last resort try this
    [vba]Application.WorksheetFunction.Text(ComboBox2, "dd-mmm-yy")[/vba]

  11. #11
    VBAX Regular
    Joined
    May 2008
    Posts
    10
    Location
    It does not work, but I try to change it into listbox instead of comboBox, it can display the date when selected, however, the date value could not input automatically into worksheet ("Attendance")

    Could any one please help !

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by apen
    It does not work
    This statement is of no value. What does not work? Which line of code? What error message? What result?
    If you want us to spend time helping, you need to invest time providing useful information.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  13. #13
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Quote Originally Posted by mdmackillop
    Check for missing VBA references. Tools/References. Uncheck any that are marked Missing
    Did you ever do this?

  14. #14
    VBAX Regular
    Joined
    May 2008
    Posts
    10
    Location
    I am sorry, how can I check the missing VBA reference. ....
    I paste my VBA as follow : Please correct me where should be re-write.

    For command button ( Data Entry)
    Private Sub CommandButton2_Click()
    UserForm2.ComboBox1.RowSource = "select!name"
    UserForm2.ComboBox2.RowSource = "select!dateB"
    UserForm2.ComboBox3.RowSource = "select!DateE"
    UserForm2.Show
    End Sub

    Thanks,
    Apen

  15. #15
    VBAX Regular
    Joined
    May 2008
    Posts
    10
    Location
    Dear mdmackillop,

    even I re-write the code as :

    VBA:
    ComboBox2 = Format(ComboBox2, "dd-mmm-yy")
    VBA tags courtesy of www.thecodenet.com

    As a last resort try this


    VBA:
    Application.WorksheetFunction.Text(ComboBox2, "dd-mmm-yy")
    VBA

    The "date" display in the comboBox is still not in date format but a value, so I reply " it does work"

    apen

  16. #16
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    The ActiveX controls prevent me from testing, but..

    My thought is:
    1) ComboBox2.Value is a string,
    2) Format(someString,"dd-mmm-yy") = someString, therefore ComboBox2.Value should be converted to a number.[VBA]ComboBox2.Value = Format(DateValue(ComboBox2.Value),"dd-mmm-yy")[/VBA]might solve the issue.

  17. #17
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by apen
    I am sorry, how can I check the missing VBA reference. ....
    In the VBE click Tools/References. Are any marked "Missing"?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •