Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
Three Lefts Three Lefts is offline
external usenet poster
 
Posts: 56
Default Elegant way to convert table of times to 24-hour format?

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   Report Post  
Posted to microsoft.public.word.newusers
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default Elegant way to convert table of times to 24-hour format?

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   Report Post  
Posted to microsoft.public.word.newusers
Three Lefts Three Lefts is offline
external usenet poster
 
Posts: 56
Default Elegant way to convert table of times to 24-hour format?

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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I convert from wingdings to times new roman medcard Microsoft Word Help 7 December 15th 08 04:05 AM
where can i get an elegant merge letter template Microsoft Word Tables 0 September 12th 07 02:32 AM
elegant resume.dot - what creates the borders? kas Tables 2 August 17th 06 10:46 PM
copying a format multiple times Jenny Microsoft Word Help 1 April 25th 05 12:22 PM
How I convert an excel table to label format? Daniella Cardoso Mailmerge 2 March 20th 05 08:47 AM


All times are GMT +1. The time now is 01:22 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"