开发者

Excel VBA Time Format as decimal with Combobox

开发者 https://www.devze.com 2023-01-30 07:07 出处:网络
Very basic, and very annoying, I have searched solution for many hours with no help... Problem: I\'m populating Combobox from named range, range is list of times (formatted as time :-), Combo seems f

Very basic, and very annoying, I have searched solution for many hours with no help...

Problem: I'm populating Combobox from named range, range is list of times (formatted as time :-), Combo seems fine, drop-down shows my times as they should be, but when selected time is formatted as a decimal number...

Excel VBA Time Format as decimal with Combobox

Here is the code (ripped down to bare minimum):

Private Sub UserForm_Initialize()
    ComboBoxTime.RowSource = "Help!Time" 
End Sub

"Help" is name of worksheet containing named range "Time"I have tried formatting different ways with no luck...

ComboBoxTime = Format(ComboBoxTime, "hh开发者_如何学Gomm")

Here is link to sample. http://www.equstom.fi/dateproblem.html

(And yes I need to populate from named range, instead for each loop, and I will set .value with code, Whole document is actually quite complex, but I included just The problem part...)


Try something like this:

Private Sub ComboBox1_Change()
With ComboBox1
  .Value = Format(.Value, "hh:mm:ss AMPM")

End With
End Sub 

HTH!

Edit This is what I see when leaving your combo. The time display works OK.

Excel VBA Time Format as decimal with Combobox

Edit 2

Found the error "invalid property":

You must set "Match Requiered" to FALSE in the combo box. If you consider that it should be "TRUE" you will have to validate by hand ...


The problem is named range I'm using, when values are formatted as time it won't work. I got it to work if values were Text! Problem has something to do with excel being in Finnish and VBA in english... I added second column next to range which copies text values to this named second range formatted as time. Quick and Dirty! (Thanks for your input Belisarius)

0

精彩评论

暂无评论...
验证码 换一张
取 消