PDA

View Full Version : Solved: Text to Time then compare



Jinky Julie
10-02-2009, 08:05 AM
Hi all...
I would like to test a cell's contents and highlight the cell if it fails...

Stumbling block is the info in the cell is an "elapsed time". (e.g. 2:48)

This is what I've started with... I know it doesn't work... Just want to illustrate where I want to go...


Dim oTable As Table
Dim etRng As Date

Set oTable = ActiveDocument.Tables(1)
With oTable
Set etRng = .Cell(3, 2).Range
If etRng < 2:20 Then etRng.Shading.BackgroundPatternColor =_ wdColorYellow

End With


I missing something (simple I'm sure)... I've tried CDate and a little "formula" I had used before... but it's just not working...

Suggestions... pushes.... etc... would be appreciated....

JJ

macropod
10-02-2009, 04:35 PM
Hi JJ,

Try:
Sub Test()
Dim oTbl As Table, oRng As Range
Set oTbl = ActiveDocument.Tables(1)
Set oRng = oTbl.Cell(3, 2).Range
oRng.MoveEnd wdCharacter, -1
If IsDate(oRng.Text) Then _
If CDate(oRng.Text) < "2:20" Then _
oRng.Shading.BackgroundPatternColor = wdColorYellow
End Sub

Jinky Julie
10-06-2009, 10:49 AM
Macropod...

You did it again!!! After some tweaking works great!!!

Thanks!!!

JJ