Format "only" dates withing text in a cell.

  • Thread starter Thread starter dave
  • Start date Start date
D

dave

I want all dates to be come bold whenever they appear in a cell with
other text, for example.

Today is 04/12/03, tomorrow will be 05/12/03.

04/12/03 & 05/12/03 should appear in a cell as bold text.

I know how to use conditional formatting, but not to pick out certain
words/dates withing text. Hope this makes sense.

Could anyone help me with this?

Thanks

Dathi Grimmur
 
dave said:
I want all dates to be come bold whenever they appear in a cell with
other text, for example.

Today is 04/12/03, tomorrow will be 05/12/03.

04/12/03 & 05/12/03 should appear in a cell as bold text.

I know how to use conditional formatting, but not to pick out certain
words/dates withing text. Hope this makes sense.

Could anyone help me with this?

Thanks

Dathi Grimmur

You cannot do this. Conditional formatting affects the whole cell, not parts
of the contents.
 
Dathi,

A Macro could do this if you were able to develop one. It would require the
understanding of the date format and be able to determine where in the
string this format existed then change the formatting of that range within
the value.

This would be a large undertaking and would cause excessive overhead as it
would have to loop through all your cells in the Worksheet or even the
Workbook. If you have hundreds of thousands of cells with a lot of Text it
could take a very long time.
 
You could run a macro whenever you were ready that would loop through your
selected cells.

But this kind of format can't be done to a formula (or just numbers).

Option Explicit
Sub testme01()

Dim myRng As Range
Dim myCell As Range
Dim iCtr As Long

Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Selection has no Text Constants"
Exit Sub
End If

For Each myCell In myRng.Cells
With myCell
For iCtr = 1 To Len(.Value)
If Mid(.Value, iCtr, 8) Like "##/##/##" Then
With .Characters(Start:=iCtr, Length:=8)
.Font.Bold = True
End With
End If
Next iCtr
End With
Next myCell

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 
Back
Top