PDA

View Full Version : Time Format Help



JJanower
10-25-2011, 03:20 AM
Hello dear Community, I have a lil problem with my date/time format, and I would appreciate if you could give me any comment about it.
In one sheet I have in 2 different columns start and endtimes, in this code down there they are on column 5 and 9 from sheet1, the times are in this format: hh:mm so it would be like this for starttime for example in Cells(2, 5) is 09:00 and endtime in Cells(2,9) is 17:00.

I am putting both of the times from both cells in a different Sheet called Worksheets("Test"), and I need to put them together in ONE CELL divided just by a " - " like it is written in the code down there: Worksheets("Test").Cells(i, j) = StartTime & "-" & EndTime I need to get it to be on one cell like this 09:00 - 17:00, but instead i am getting seconds and it is putting it like this:
09:00:00 - 17:00:00

is there a way within my code to change the format of the time for it to be hh:mm - hh:mm, without the seconds.

Dim StartTime As Date
Dim EndTime As Date

RowCount = Worksheets("Test").Cells(1, 1).CurrentRegion.Rows.Count
Columncount = Worksheets("Test").Cells(1, 1).CurrentRegion.Columns.Count

For i = 2 To RowCount 'end of the Test team/name
For j = 3 To Columncount 'end of sheet1 dates
TempData = Worksheets("Test").Cells(1, j) & Worksheets("Test").Cells(i,

For k = 2 To 3208
If Cells(k, 1) & Cells(k, 4) = TempData Then
StartTime = Cells(k, 5)
EndTime = Cells(k, 9)
Worksheets("Test").Cells(i, j) = StartTime & "-" & EndTime

ElseIf Worksheets("Test").Cells(i, j) = "" Then
Worksheets("Test").Cells(i, j) = "Day Off"

End If
Next k
Next j
Next i
Thank you for your time
Yours Truly,
Jaime

Sorin Sion
10-25-2011, 08:08 AM
Try this instead of Worksheets("Test").Cells(i, j) = StartTime & "-" & EndTime:
Worksheets("Test").Cells(i, j) = Format(StartTime, "hh:mm") & "-" & Format(EndTime,"hh:mm")

JJanower
10-25-2011, 08:31 AM
man you are the best!!
it worked perfectl
thx alot ♥!!!!

Sorin Sion
10-25-2011, 01:07 PM
You're welcome :)