Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default xl97 userform combobox time

How do I write a routine (xl97) to fill a combo box on a userform with
the time starting at 12:00 AM and ending at 11:45 PM?

I populated a combo box from the times on a worksheet and wrote this. It
works. (cells A1 thru A96 have 12:00 AM, 12:15 AM, etc...)

Sub build_combobox1()

Dim x As Date

With Worksheets("Sheet3")
For x = 1 To 96
ComboBox1.AddItem .Cells(x, 1)
Next x
End With

End Sub

But I rather build the data instead of getting it. Something like this
which does not work. (the value of x I can't figure out)

Sub build_combobox1()

Dim x As Date

For x = 1200 To 2400 Step 15
ComboBox1.AddItem Format(x, "hh:mm AMPM")

Next x

End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default xl97 userform combobox time

Hi Pete,

There are 96 quarter hours per day, starting at 0 or midnight:

Sub test()
Dim i As Long
Dim q As Date
Dim t As Date

q = 1 / 96
t = 0

For i = 0 To 95
Debug.Print t, Format(t, "hh:mm AMPM")
t = t + q
Next

End Sub

You could declare q & t as Single or Double if you want time as fractions of
a day for some other purpose.

Regards,
Peter T

"Pete" wrote in message
...
How do I write a routine (xl97) to fill a combo box on a userform with
the time starting at 12:00 AM and ending at 11:45 PM?

I populated a combo box from the times on a worksheet and wrote this. It
works. (cells A1 thru A96 have 12:00 AM, 12:15 AM, etc...)

Sub build_combobox1()

Dim x As Date

With Worksheets("Sheet3")
For x = 1 To 96
ComboBox1.AddItem .Cells(x, 1)
Next x
End With

End Sub

But I rather build the data instead of getting it. Something like this
which does not work. (the value of x I can't figure out)

Sub build_combobox1()

Dim x As Date

For x = 1200 To 2400 Step 15
ComboBox1.AddItem Format(x, "hh:mm AMPM")

Next x

End Sub





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default xl97 userform combobox time

Thanks Peter, that is the solution to my problem.


"Peter T" <peter_t@discussions wrote in
:

Hi Pete,

There are 96 quarter hours per day, starting at 0 or midnight:

Sub test()
Dim i As Long
Dim q As Date
Dim t As Date

q = 1 / 96
t = 0

For i = 0 To 95
Debug.Print t, Format(t, "hh:mm AMPM")
t = t + q
Next

End Sub

You could declare q & t as Single or Double if you want time as
fractions of a day for some other purpose.

Regards,
Peter T

"Pete" wrote in message
...
How do I write a routine (xl97) to fill a combo box on a userform
with the time starting at 12:00 AM and ending at 11:45 PM?

I populated a combo box from the times on a worksheet and wrote this.
It works. (cells A1 thru A96 have 12:00 AM, 12:15 AM, etc...)

Sub build_combobox1()

Dim x As Date

With Worksheets("Sheet3")
For x = 1 To 96
ComboBox1.AddItem .Cells(x, 1)
Next x
End With

End Sub

But I rather build the data instead of getting it. Something like
this which does not work. (the value of x I can't figure out)

Sub build_combobox1()

Dim x As Date

For x = 1200 To 2400 Step 15
ComboBox1.AddItem Format(x, "hh:mm AMPM")

Next x

End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default xl97 userform combobox time

Also, you could add to your combo box like this:

'in a Form module containing ComboBox1
Private Sub UserForm_Initialize()
Dim i As Long
Dim q As Date
Dim t As Date
Dim asTimes(0 To 95) As String

q = 1 / 96
t = 0

For i = 0 To 95
asTimes(i) = Format(t, "hh:mm AMPM")
t = t + q
Next

Me.ComboBox1.List = asTimes()
Me.ComboBox1.ListIndex = 0

End Sub

Regards,
Peter T

"Pete" wrote in message
...
Thanks Peter, that is the solution to my problem.


"Peter T" <peter_t@discussions wrote in
:

Hi Pete,

There are 96 quarter hours per day, starting at 0 or midnight:

Sub test()
Dim i As Long
Dim q As Date
Dim t As Date

q = 1 / 96
t = 0

For i = 0 To 95
Debug.Print t, Format(t, "hh:mm AMPM")
t = t + q
Next

End Sub

You could declare q & t as Single or Double if you want time as
fractions of a day for some other purpose.

Regards,
Peter T

"Pete" wrote in message
...
How do I write a routine (xl97) to fill a combo box on a userform
with the time starting at 12:00 AM and ending at 11:45 PM?

I populated a combo box from the times on a worksheet and wrote this.
It works. (cells A1 thru A96 have 12:00 AM, 12:15 AM, etc...)

Sub build_combobox1()

Dim x As Date

With Worksheets("Sheet3")
For x = 1 To 96
ComboBox1.AddItem .Cells(x, 1)
Next x
End With

End Sub

But I rather build the data instead of getting it. Something like
this which does not work. (the value of x I can't figure out)

Sub build_combobox1()

Dim x As Date

For x = 1200 To 2400 Step 15
ComboBox1.AddItem Format(x, "hh:mm AMPM")

Next x

End Sub








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Value From ComboBox On UserForm jlclyde Excel Discussion (Misc queries) 3 October 16th 09 01:43 PM
ComboBox on a UserForm LLoyd Excel Worksheet Functions 2 February 20th 08 09:01 PM
XL97 vs XL? Recalc-time CLR Excel Discussion (Misc queries) 10 November 30th 05 01:57 PM
Userform w/ComboBox D.Parker Excel Discussion (Misc queries) 2 May 6th 05 04:28 PM
ComboBox on UserForm Michel[_4_] Excel Programming 2 July 31st 04 10:11 PM


All times are GMT +1. The time now is 10:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"