Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: George Evans   on Oct 10 In MS Office Category.

  
Question Answered By: Michele Grant   on Oct 10

The problem isn't your CDate as such.

BTW

Range("DATEFIELD").value = CDate(Range("DATEFIELD").value)

isn't a circular  reference - it's just a reassignment to itself.

The problem is that CDate won't take your multi-cell range. You need to
loop through the cells. E.g.

Option Explicit

Private Sub CommandButton1_Click()
Dim cell  As Range
For Each Cell In Range("DateField")
Cell.Formula = CDate(Cell.Formula)
Next Cell
End Sub

This might change the format of your date  values. An alternative is to
check whether it's a string that's in the cell, and only convert if it is.
I.e.

Private Sub CommandButton1_Click()
Dim Cell As Range
For Each Cell In Range("DateField")
If TypeName(Cell.Value) = "String" Then
Cell.Formula = CDate(Cell.Formula)
End If
Next Cell
End Sub

Share: