H
hgrove
Frank Kabel wrote...
...
I'll grant that all design decisions are in part subjective, but i
this case there's the issue about what would cause the least harm
That'd have to be determined empirically.
I still think separating entry and conversion is the most workable wa
to go, and I'm dead certain no individual user ever needs multipl
formats. But if they did, they could completely define how they wante
ambiguous entries interpretted. Just enter them in another range lik
the following.
d
dd
md
mdd
mmd
mdy
mmdd
mddy
mdyy
mmdy
mmddyy
mmddyyyy
You'd probably want to use
d
dd
dm
ddm
dmm
dmy
ddmm
ddmy
dmyy
dmmy
ddmmyy
ddmmyyyy
Name this range something long & complicated like
DateEntryAmbiguityResolution
(or define it with a constant array), and you could use a batc
conversion macro like the following.
Code
-------------------
Sub csd()
Dim f0 As String, f1 As String
Dim i As Long, j As Long, n As Long
Dim ymd(1 To 3) As String, cm As String, cy As String
Dim c As Range, dear As Variant, v As Variant
If Not TypeOf Selection Is Range Then Exit Sub
dear = Evaluate("DateEntryAmbiguityResolution")
cm = Format(Now, "mm")
cy = Format(Now, "yyyy")
For Each c In Selection.Cells
If Not (c.HasFormula Or VarType(c.Value) = vbDate _
Or c.Text Like "*[!0-9 ]*") Then
f0 = Application.Substitute(c.Text, " ", "")
n = Len(f0)
f1 = ""
For Each v In dear
ymd(1) = ""
ymd(2) = ""
ymd(3) = ""
If Len(v) = n Then
For i = 1 To n
j = InStr(1, "ymd", Mid(v, i, 1))
ymd(j) = ymd(j) & Mid(f0, i, 1)
Next i
If ymd(1) = "" Then ymd(1) = cy
i = CLng(ymd(1))
If i < 30 Then ymd(1) = Format(2000 + i, "0000")
If i < 1900 Then ymd(1) = Format(1900 + i, "0000")
If ymd(2) = "" Then ymd(2) = cm
f1 = ymd(1) & "-" & ymd(2) & "-" & ymd(3)
If IsNumeric(Evaluate("--""" & f1 & """")) Then Exit For
f1 = ""
End If
Next v
If f1 <> "" Then
c.NumberFormat = "General"
c.Formula = f1
End If
End If
Next c
End Sub
-------------------
This isn't internationalized, but it could be by replacing the "ymd
string constant with a variable. That variable would be set by locatin
a blank cell, changing it's .NumberFormat property to "ymd" and storin
its .NumberFormatLocal property in this new variable (then restorin
its original format). If I'm right about this, this macro and define
name combination provides the equivalent functionality of your entir
add-in. Actually, it'd provide more because it could handle singl
digit dates, 4-digit dates like 7799, 9977 and 1234, and bypass 5- an
7-digit numbers.
I still don't see why this requires a +500KB add-in. The cor
functionality just ain't that complicated
...
...Now we could argue what would be the better (better in this
case: easier to use for the end-user) approach. I like your idea
but dislike the idea of another hotkey.
I'll grant that all design decisions are in part subjective, but i
this case there's the issue about what would cause the least harm
That'd have to be determined empirically.
I still think separating entry and conversion is the most workable wa
to go, and I'm dead certain no individual user ever needs multipl
formats. But if they did, they could completely define how they wante
ambiguous entries interpretted. Just enter them in another range lik
the following.
d
dd
md
mdd
mmd
mdy
mmdd
mddy
mdyy
mmdy
mmddyy
mmddyyyy
You'd probably want to use
d
dd
dm
ddm
dmm
dmy
ddmm
ddmy
dmyy
dmmy
ddmmyy
ddmmyyyy
Name this range something long & complicated like
DateEntryAmbiguityResolution
(or define it with a constant array), and you could use a batc
conversion macro like the following.
Code
-------------------
Sub csd()
Dim f0 As String, f1 As String
Dim i As Long, j As Long, n As Long
Dim ymd(1 To 3) As String, cm As String, cy As String
Dim c As Range, dear As Variant, v As Variant
If Not TypeOf Selection Is Range Then Exit Sub
dear = Evaluate("DateEntryAmbiguityResolution")
cm = Format(Now, "mm")
cy = Format(Now, "yyyy")
For Each c In Selection.Cells
If Not (c.HasFormula Or VarType(c.Value) = vbDate _
Or c.Text Like "*[!0-9 ]*") Then
f0 = Application.Substitute(c.Text, " ", "")
n = Len(f0)
f1 = ""
For Each v In dear
ymd(1) = ""
ymd(2) = ""
ymd(3) = ""
If Len(v) = n Then
For i = 1 To n
j = InStr(1, "ymd", Mid(v, i, 1))
ymd(j) = ymd(j) & Mid(f0, i, 1)
Next i
If ymd(1) = "" Then ymd(1) = cy
i = CLng(ymd(1))
If i < 30 Then ymd(1) = Format(2000 + i, "0000")
If i < 1900 Then ymd(1) = Format(1900 + i, "0000")
If ymd(2) = "" Then ymd(2) = cm
f1 = ymd(1) & "-" & ymd(2) & "-" & ymd(3)
If IsNumeric(Evaluate("--""" & f1 & """")) Then Exit For
f1 = ""
End If
Next v
If f1 <> "" Then
c.NumberFormat = "General"
c.Formula = f1
End If
End If
Next c
End Sub
-------------------
This isn't internationalized, but it could be by replacing the "ymd
string constant with a variable. That variable would be set by locatin
a blank cell, changing it's .NumberFormat property to "ymd" and storin
its .NumberFormatLocal property in this new variable (then restorin
its original format). If I'm right about this, this macro and define
name combination provides the equivalent functionality of your entir
add-in. Actually, it'd provide more because it could handle singl
digit dates, 4-digit dates like 7799, 9977 and 1234, and bypass 5- an
7-digit numbers.
I still don't see why this requires a +500KB add-in. The cor
functionality just ain't that complicated