Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Storing times in an array

Hi -
I'm looking for a way to store times in an array in order to populate
a combo box with every half hour during the day. Is this possible?
Right now, I've entered the times as strings, for example: 8:00a,
8:30a, .....etc. This is in a user form. However, when I want to
write the selected time to my Excel sheet, I need it to recognize it
as a time. Can anyone help with this? Thanks alot,
Steve

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Storing times in an array

Steve,

No need to create an array:

Sub TimesInComboBox()
Dim i As Integer

With UserForm1.ComboBox1
.Clear
For i = 0 To 47
.AddItem Format(i / 48, "hh:mm:ss")
Next i
End With

Load UserForm1
UserForm1.Show
End Sub


HTH,
Bernie
MS Excel MVP


wrote in message oups.com...
Hi -
I'm looking for a way to store times in an array in order to populate
a combo box with every half hour during the day. Is this possible?
Right now, I've entered the times as strings, for example: 8:00a,
8:30a, .....etc. This is in a user form. However, when I want to
write the selected time to my Excel sheet, I need it to recognize it
as a time. Can anyone help with this? Thanks alot,
Steve



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Storing times in an array

You don't necessarily need an array. You can use AddItem to add each time to
the combobox one at a time.

Dim StartTime As Date
Dim EndTime As Date
Dim OneTime As Date
StartTime = TimeValue("08:00:00 AM")
EndTime = TimeValue("05:01:00 PM") ' note 01 minute to handle rounding
Me.ComboBox1.Clear
For OneTime = StartTime To EndTime Step TimeSerial(0, 30, 0)
Me.ComboBox1.AddItem Format(OneTime, "hh:mm:ss AMPM")
Next OneTime


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


wrote in message
oups.com...
Hi -
I'm looking for a way to store times in an array in order to populate
a combo box with every half hour during the day. Is this possible?
Right now, I've entered the times as strings, for example: 8:00a,
8:30a, .....etc. This is in a user form. However, when I want to
write the selected time to my Excel sheet, I need it to recognize it
as a time. Can anyone help with this? Thanks alot,
Steve


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Storing times in an array

On Jul 9, 1:08 pm, "Chip Pearson" wrote:
You don't necessarily need anarray. You can use AddItem to add eachtimeto
the combobox one at atime.

Dim StartTime As Date
Dim EndTime As Date
Dim OneTime As Date
StartTime = TimeValue("08:00:00 AM")
EndTime = TimeValue("05:01:00 PM") ' note 01 minute to handle rounding
Me.ComboBox1.Clear
For OneTime = StartTime To EndTime Step TimeSerial(0, 30, 0)
Me.ComboBox1.AddItem Format(OneTime, "hh:mm:ss AMPM")
Next OneTime

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consultingwww.cpearson.com
(email on the web site)

wrote in message

oups.com...

Hi -
I'm looking for a way to store times in anarrayin order to populate
a combo box with every half hour during the day. Is this possible?
Right now, I've entered the times as strings, for example: 8:00a,
8:30a, .....etc. This is in a user form. However, when I want to
write the selectedtimeto my Excel sheet, I need it to recognize it
as atime. Can anyone help with this? Thanks alot,
Steve


Perfect - both options work, thanks gentlemen!!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Storing times in an array

On Jul 9, 1:08 pm, "Chip Pearson" wrote:
You don't necessarily need anarray. You can use AddItem to add eachtimeto
the combobox one at atime.

Dim StartTime As Date
Dim EndTime As Date
Dim OneTime As Date
StartTime = TimeValue("08:00:00 AM")
EndTime = TimeValue("05:01:00 PM") ' note 01 minute to handle rounding
Me.ComboBox1.Clear
For OneTime = StartTime To EndTime Step TimeSerial(0, 30, 0)
Me.ComboBox1.AddItem Format(OneTime, "hh:mm:ss AMPM")
Next OneTime

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consultingwww.cpearson.com
(email on the web site)

wrote in message

oups.com...

Hi -
I'm looking for a way to store times in anarrayin order to populate
a combo box with every half hour during the day. Is this possible?
Right now, I've entered the times as strings, for example: 8:00a,
8:30a, .....etc. This is in a user form. However, when I want to
write the selectedtimeto my Excel sheet, I need it to recognize it
as atime. Can anyone help with this? Thanks alot,
Steve


Hey guys -
One more question, now that I've got that combo box populated with
every half hour. I'm doing some validation to make sure that the
start time (combo box) if changed is earlier than the end time
(another combo box). In other words, if the user selects 10:00AM for
the start time, and 9:00AM for the end time, it should spring an error
box. When I use the property combobox1.value to compare to
combobox2.value, it only looks at the numbers, and not the AM versus
PM. Is there another property to use so that it will actually compare
them as times? Currently, it thinks that 02:00PM is earlier than
11:00AM because 2 is less than 11.
My code is:

If cboEndTime.Value < cboStartTime.Value Then
MsgBox("Start time must be earlier than the end time.")
cboEndTime = cboStartTime.Value
End If

Thanks a ton!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Storing times in an array

Try

If TimeValue(cboEndTime.Value) < TimeValue(cboStartTime.Value) Then

HTH,
Bernie
MS Excel MVP


wrote in message ps.com...
On Jul 9, 1:08 pm, "Chip Pearson" wrote:
You don't necessarily need anarray. You can use AddItem to add eachtimeto
the combobox one at atime.

Dim StartTime As Date
Dim EndTime As Date
Dim OneTime As Date
StartTime = TimeValue("08:00:00 AM")
EndTime = TimeValue("05:01:00 PM") ' note 01 minute to handle rounding
Me.ComboBox1.Clear
For OneTime = StartTime To EndTime Step TimeSerial(0, 30, 0)
Me.ComboBox1.AddItem Format(OneTime, "hh:mm:ss AMPM")
Next OneTime

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consultingwww.cpearson.com
(email on the web site)

wrote in message

oups.com...

Hi -
I'm looking for a way to store times in anarrayin order to populate
a combo box with every half hour during the day. Is this possible?
Right now, I've entered the times as strings, for example: 8:00a,
8:30a, .....etc. This is in a user form. However, when I want to
write the selectedtimeto my Excel sheet, I need it to recognize it
as atime. Can anyone help with this? Thanks alot,
Steve


Hey guys -
One more question, now that I've got that combo box populated with
every half hour. I'm doing some validation to make sure that the
start time (combo box) if changed is earlier than the end time
(another combo box). In other words, if the user selects 10:00AM for
the start time, and 9:00AM for the end time, it should spring an error
box. When I use the property combobox1.value to compare to
combobox2.value, it only looks at the numbers, and not the AM versus
PM. Is there another property to use so that it will actually compare
them as times? Currently, it thinks that 02:00PM is earlier than
11:00AM because 2 is less than 11.
My code is:

If cboEndTime.Value < cboStartTime.Value Then
MsgBox("Start time must be earlier than the end time.")
cboEndTime = cboStartTime.Value
End If

Thanks a ton!



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
Storing an array in a cell Blue Max Excel Worksheet Functions 9 March 18th 09 12:54 PM
Storing a vba lookup in an array erikhs[_19_] Excel Programming 1 August 1st 06 04:49 PM
I want to see how many times each number occurs in an array. eingram Excel Discussion (Misc queries) 3 June 21st 06 02:53 AM
Storing text in an array Daniel Bonallack Excel Programming 9 December 14th 04 07:42 AM
storing financial data in array Fred[_19_] Excel Programming 1 September 13th 04 02:23 AM


All times are GMT +1. The time now is 12:27 PM.

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

About Us

"It's about Microsoft Excel"