Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.newusers
|
|||
|
|||
![]()
I have a rather large table one column of which contains times in
12-hour format without the colon: 642a, 1009p, etc. (no seconds) Can anyone think of a clever way to convert that column to standard 24-hour format: 06:42:00, 20:09:00, etc.? |
#2
![]()
Posted to microsoft.public.word.newusers
|
|||
|
|||
![]()
Hi Three Lefts,
Here's a macro to do the job: Sub TimeConvert() Dim i As Integer Dim j As Integer Dim strTxt As String If Selection.Information(wdWithInTable) = True Then With Selection.Tables(1) j = 1 For i = 1 To .Rows.Count If Len(.Cell(i, j).Range.Text) 2 Then strTxt = Left(.Cell(i, j).Range.Text, Len(.Cell(i, j).Range.Text) - 2) If Len(strTxt) = 4 Then strTxt = "0" & strTxt If Left(strTxt, 2) = "12" Then strTxt = "00" & Right(strTxt, 3) If Right(strTxt, 1) = "p" Then strTxt = Left(Replace(strTxt, Left(strTxt, 2), Left(strTxt, 2) + 12 & ":"), 5) Else strTxt = Left(Replace(strTxt, Left(strTxt, 2), Left(strTxt, 2) & ":"), 5) End If strTxt = strTxt & ":00" .Cell(i, j).Range.Text = strTxt End If Next End With End If End Sub As coded, the macro works on the first column in the table. To change the column, change 'j = 1' to 'j = #' where # is the column number. To update the table, simply select anywhere within the table, press Alt-F8 and choose the 'TimeConvert' macro. Note: There's no error checking in the code so, if you've got anything else in the column, it's liable to get munged. Cheers -- macropod [MVP - Microsoft Word] ------------------------- "Three Lefts" wrote in message ... I have a rather large table one column of which contains times in 12-hour format without the colon: 642a, 1009p, etc. (no seconds) Can anyone think of a clever way to convert that column to standard 24-hour format: 06:42:00, 20:09:00, etc.? |
#3
![]()
Posted to microsoft.public.word.newusers
|
|||
|
|||
![]()
On Sat, 12 Apr 2008 13:34:34 +1000, "macropod"
wrote: Hi Three Lefts, Here's a macro to do the job: Sub TimeConvert() Dim i As Integer Dim j As Integer Dim strTxt As String If Selection.Information(wdWithInTable) = True Then With Selection.Tables(1) j = 1 For i = 1 To .Rows.Count If Len(.Cell(i, j).Range.Text) 2 Then strTxt = Left(.Cell(i, j).Range.Text, Len(.Cell(i, j).Range.Text) - 2) If Len(strTxt) = 4 Then strTxt = "0" & strTxt If Left(strTxt, 2) = "12" Then strTxt = "00" & Right(strTxt, 3) If Right(strTxt, 1) = "p" Then strTxt = Left(Replace(strTxt, Left(strTxt, 2), Left(strTxt, 2) + 12 & ":"), 5) Else strTxt = Left(Replace(strTxt, Left(strTxt, 2), Left(strTxt, 2) & ":"), 5) End If strTxt = strTxt & ":00" .Cell(i, j).Range.Text = strTxt End If Next End With End If End Sub As coded, the macro works on the first column in the table. To change the column, change 'j = 1' to 'j = #' where # is the column number. To update the table, simply select anywhere within the table, press Alt-F8 and choose the 'TimeConvert' macro. Note: There's no error checking in the code so, if you've got anything else in the column, it's liable to get munged. Cheers Works like a charm. Thanks a bunch. That saved me a lot of time, and I learned something to boot. Where do I send the beer? ;-) |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
how do I convert from wingdings to times new roman | Microsoft Word Help | |||
where can i get an elegant merge letter template | Tables | |||
elegant resume.dot - what creates the borders? | Tables | |||
copying a format multiple times | Microsoft Word Help | |||
How I convert an excel table to label format? | Mailmerge |