Your complaints are entirely legitimate, just as those from the 19 pages before. Obviously, there is no avail in addressing Microsoft, as it turns out. I take it so that they, in their effort to meet formal habits of financials,
loose interest in the application in the other less lucrative branches. We may abandon Excel, but, as you remark, sticking to has its own benefits.
Anyhow, there were bidden several ways, how some faults can
be treated. At least the amendment of wrong conversion of CAS ID’s can be a next useful
example of such a working method. (Poor old CAV nomenclature does not deserve such a barbarity of newer Excel.) The gist is in the obstinate format of CAS (something like 0-00-0) so that it is clear, which part of a wrongly
created date should be linked to the part of CAV ID. As the issues of this kind may be numerous, I tried to create a macro in rather a slightly comfortable package.
The sub browses the cells. If correctly transferred format (with hyphens) is encountered, it does nothing. In the opposite, however, the proper transposition to individual ID parts takes place. The
movement is dependent of the format of the wrongly created date and accordingly processed.
In calling it, you have to have one or several cells with doubtfully transferred cells selected; the proof will run on the hinted selection.
Option Explicit
Sub Date2CAS()
'Sub corrects wrongly converted CAS ID's from date to string format
Dim S As Variant, MonthLeading As Variant, T As Variant, D1 As Variant, D2 As Variant
Dim MB As Long
Dim F As String
Dim Hyphen As Boolean
Dim Cell As Range
Set S = Selection
If S.Count = 1 Then
MB = MsgBox("- downward list from here (Yes)" & vbCrLf & _
" (can't be undone)" & vbCrLf & _
"- only this single cell (No)", _
vbYesNoCancel + vbDefaultButton2, _
"Fix wrong dates into correct CAS numbers")
If MB = vbCancel Then Exit Sub
If MB = vbYes Then
Set S = Range(S, S.End(xlDown))
End If
End If
Application.ScreenUpdating = False
For Each Cell In S
F = Cell.NumberFormat
Cell.NumberFormat = "@"
Hyphen = InStr(1, Cell, "-") > 0
If Not Hyphen Then
T = Cell.Value
If IsNull(MonthLeading) Then _
MonthLeading = InStr(F, "m") < InStr(F, "d")
If Not MonthLeading Then
D1 = Day(T): D2 = Month(T)
Else
D2 = Day(T): D1 = Month(T)
End If
Cell.Value = Year(T) & "-" & Format(D2, "00") & "-" & D1
End If
Next Cell
Application.ScreenUpdating = True
End Sub
::After correcting a heavy mistake.
Apologies and regards
PB