我遇到了一项具有挑战性的任务,使用许多解决方法都无法解决该任务。
在一列中我有日期,日期可以采用以下三种格式:
1) 简单的日/月/年
2) dd/mm/yy,但周围可能有“之前、之后或关于”字样。任何
其中之一,在这种情况下我们只需要删除这些词即可。
3) 数字格式的日期。长十进制值,例如 1382923.2323
但实际上我可以在转换后从中获取日期。
文件已上传至此处。日期格式宏链接 https://docs.google.com/file/d/0B7gzonuQsNbvQXNzWFhta0ZqUWs/edit?usp=sharing
我编写了以下代码,但它给出了错误的结果。
Sub FormatDates_Mine()
ManualSheet.Activate
ManualSheet.Cells.Hyperlinks.Delete
ManualSheet.Cells.Interior.ColorIndex = xlNone
ManualSheet.Cells.Font.Color = RGB(0, 0, 0)
lastRow = ManualSheet.Range("A" & Rows.Count).End(xlUp).Row
Col = "A"
For i = 2 To lastRow
Cells(i, Col) = Trim(Replace(Cells(i, Col), vbLf, "", 1, , vbTextCompare))
If InStr(1, Cells(i, Col), "about", vbTextCompare) <> 0 Then
Cells(i, Col) = Trim(Replace(Cells(i, Col), "about", "", 1, , vbTextCompare))
Cells(i, Col).Interior.Color = RGB(217, 151, 149)
End If
If InStr(1, Cells(i, Col), "after", vbTextCompare) <> 0 Then
Cells(i, Col) = Trim(Replace(Cells(i, Col), "after", "", 1, , vbTextCompare))
Cells(i, Col).Interior.Color = RGB(228, 109, 10)
End If
If InStr(1, Cells(i, Col), "before", vbTextCompare) <> 0 Then
Cells(i, Col) = Trim(Replace(Cells(i, Col), "before", "", 1, , vbTextCompare))
Cells(i, Col).Interior.Color = RGB(228, 109, 10)
End If
DateParts = Split(Cells(i, Col), "/", , vbTextCompare)
Cells(i, Col) = Format(Cells(i, Col), "dd/mm/yyyy")
Next i
Range("D:E").HorizontalAlignment = xlCenter
End Sub
文件已上传至此处。日期格式宏链接 https://docs.google.com/file/d/0B7gzonuQsNbvQXNzWFhta0ZqUWs/edit?usp=sharing
请帮忙!