我有一個以逗號分隔的日期值的單元格,例如
27.02.2022, 09.02.2022, 09.02.2022, 26.02.2022, 13.02.2022, 17.02.2022, 16.02.2022, 27.02.2022, 21.11.2022, 14.11.2022, 25.12.2022, 02.03.2022, 02.03.2022, 04.04.2022, 02.03.2022, 07.02.2022, 02.03.2022, 17.11.2022, 04.04.2022, 23.02.2022, 25.02.2022, 28.02.2022, 01.03.2022, 03.02.2022, 28.11.2022, 16.02.2022, 02.02.2022, 01.03.2022, 31.03.2022, 17.02.2022, 05.11.2022, 20.02.2022, 02.02.2022, 13.02.2022, 16.02.2022, 29.09.2022, 16.02.2022, 16.02.2022, 02.03.2022, 02.03.2022, 02.03.2022, 02.03.2022, 02.03.2022, 02.03.2022, 02.03.2022, 24.12.2022, 02.02.2022, 02.02.2022, 09.02.2022, 09.02.2022, 09.02.2022, 26.12.2022, 19.02.2022, 25.02.2022, 15.02.2022, 02.02.2022, 03.02.2022, 18.02.2022, 23.12.2022, 02.02.2022, 02.02.2022, 10.02.2022, 02.02.2022, 02.02.2022, 02.02.2022, 02.02.2022, 20.02.2022, 17.02.2022, 20.02.2022, 12.03.2022, 18.02.2022, 02.02.2022, 02.02.2022, 05.11.2022, 21.11.2022, 23.11.2022, 09.02.2022, 28.11.2022, 01.03.2022, 01.03.2022, 02.03.2022, 04.04.2022, 12.02.2022, 12.02.2022, 01.03.2022, 01.03.2022, 11.02.2022, 23.02.2022, 16.02.2022, 28.02.2022, 16.02.2022, 16.02.2022, 02.02.2022, 02.02.2022, 02.02.2022, 02.02.2022, 02.02.2022, 02.02.2022, 09.11.2022, 28.02.2022, 13.02.2022, 13.02.2022, 03.02.2022, 03.02.2022, 03.02.2022, 03.02.2022, 03.02.2022, 03.02.2022, 02.03.2022, 02.03.2022, 21.11.2022, 12.02.2022, 17.02.2022, 23.02.2022, 02.03.2022, 02.03.2022, 02.03.2022, 21.11.2022, 10.02.2022, 10.02.2022, 03.02.2022, 18.03.2022, 18.12.2022, 18.12.2022, 02.02.2022, 17.11.2022, 28.02.2022, 02.02.2022, 02.02.2022, 31.03.2022, 02.02.2022, 28.02.2022, 16.02.2022, 16.02.2022, 16.02.2022, 17.11.2022, 02.03.2022, 24.10.2022, 09.11.2022, 21.02.2022, 01.03.2022, 17.02.2022, 21.11.2022, 11.11.2022, 17.02.2022, 03.03.2022, 16.02.2022, 16.02.2022, 02.03.2022, 23.11.2022, 02.02.2022, 27.02.2022, 26.02.2022, 02.03.2022, 02.03.2022, 02.03.2022, 02.03.2022, 02.03.2022, 02.03.2022, 02.03.2022, 02.03.2022, 02.03.2022, 31.03.2022, 28.11.2022, 24.12.2022, 24.12.2022, 03.02.2022, 03.04.2022, 15.02.2022, 22.02.2022, 01.03.2022, 01.03.2022, 28.02.2022, 16.02.2022, 16.02.2022, 16.02.2022, 19.02.2022, 01.03.2022, 01.03.2022, 20.02.2022, 20.02.2022, 20.02.2022, 20.02.2022, 04.02.2022, 19.02.2022, 13.02.2022, 13.02.2022, 20.02.2022, 20.02.2022, 28.02.2022, 17.11.2022, 16.02.2022, 16.02.2022, 09.11.2022, 13.02.2022, 28.02.2022, 28.02.2022, 28.02.2022, 28.02.2022, 21.11.2022, 10.02.2022, 28.11.2022, 05.11.2022, 23.12.2022, 25.02.2022, 17.02.2022, 25.02.2022, 25.02.2022, 12.03.2022, 12.03.2022, 23.12.2022, 26.12.2022, 16.11.2022, 16.02.2022, 16.02.2022, 16.02.2022, 07.02.2022, 16.02.2022, 07.02.2022, 07.02.2022, 28.02.2022, 01.03.2022, 07.02.2022, 25.12.2022, 28.02.2022, 28.02.2022, 28.02.2022, 28.02.2022, 23.02.2022, 05.11.2022, 01.03.2022, 01.03.2022, 14.02.2022, 21.11.2022, 16.02.2022, 16.02.2022, 16.02.2022, 16.02.2022, 13.02.2022, 09.02.2022, 28.02.2022, 13.02.2022, 23.02.2022, 15.02.2022, 16.02.2022, 16.02.2022, 16.02.2022, 21.02.2022, 21.02.2022, 05.02.2022, 28.02.2022, 24.10.2022, 04.04.2022, 04.04.2022, 16.02.2022, 29.09.2022, 09.02.2022, 09.02.2022, 09.02.2022, 24.12.2022, 22.02.2022, 22.02.2022, 14.02.2022, 18.03.2022, 18.12.2022, 29.09.2022, 23.11.2022, 14.11.2022, 03.02.2022, 03.02.2022, 03.02.2022, 03.02.2022, 03.02.2022, 13.02.2022, 28.11.2022, 21.11.2022, 21.02.2022, 05.11.2022, 25.02.2022, 13.02.2022, 06.02.2022, 23.12.2022, 15.02.2022, 22.02.2022, 22.02.2022, 10.02.2022, 07.02.2022, 28.02.2022, 28.02.2022, 28.02.2022, 18.12.2022, 15.02.2022, 24.12.2022, 17.11.2022, 12.02.2022, 12.03.2022, 12.03.2022
我需要獲取最舊的日期值來分隔單元格。嘗試修改此解決方案:
=MIN(IFERROR(DATEVALUE(TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",999)),(ROW(INDIRECT("1:" & LEN(A1) -LEN(SUBSTITUTE(A1,",","")) 1))-1)*999 1,999))),0))
在這里找到。但似乎,我的單元格中有太多日期,將 999 更改為 9999 并沒有幫助。
我在目標單元格中??得到 0。但在較短的細胞上,解決方案確實有效。
任何幫助將不勝感激。需要公式或 VBA 函式。謝謝!
uj5u.com熱心網友回復:
如果您使用 ms365 訪問最新功能,您可以嘗試:
=MIN(--TEXTSPLIT(A1,", "))
如果您的辦公室無法識別日期模式,您可能需要替換點:
=MIN(--TEXTSPLIT(SUBSTITUTE(A1,".","-"),,", "))
如果您還沒有,請TEXTSPLIT()嘗試FILTERXML():
=MIN(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A1,".","-"),", ","</s><s>")&"</s></t>","//s"))
或者,如果您沒有 ms365(但 Excel 2013 或更高版本)并且您不想使用 CSE,則使用 xpath 本身。
uj5u.com熱心網友回復:
請測驗下一個 VBA 函式,在任何 Excel 版本中作業:
Function ExtractOldestDate(strD As String) As Date
Dim arrD: arrD = Split(strD, ", ")
Dim i As Long, oldD As Date, arr, compD As Date
oldD = DateSerial(2050, 1, 1)
For i = 0 To UBound(arrD)
arr = Split(arrD(i), "."): compD = DateSerial(CLng(arr(2)), CLng(arr(1)), CLng(arr(0)))
If compD < oldD Then oldD = compD
Next
ExtractOldestDate = oldD
End Function
上述函式將以這種方式處理一系列 ( Date) 格式為“dd.mm.yyyy”或“dmyyyy”的字串。為了處理不同的字串格式,DateSerial應該進行相應的調整。我基本上是指該字串中使用的分隔符和日/月/年位置...
它可以在 VBA 中進行測驗,使用下一個測驗Sub:
Sub testExtrOldD()
Dim strD As String
strD = Range("A1").value
Debug.Print ExtractOldestDate(strD)
End Sub
作為 UDF,從單元格中呼叫為:
=ExtractOldestDate(A1)
保留公式的單元格必須格式化為日期...
uj5u.com熱心網友回復:
如果您當前的 Windows 默認日期格式與串列中的日期格式不匹配,那么您可能需要將它們拆分為日、月和年,以將它們可靠地轉換為數字日期:
Public Function ExtractOldestDateFromStringList(ByVal ListOfDateStrings As String, ByVal Delimiter As String, ByVal DateFormat As String) As Variant
Dim ArrayOfDateStrings() As String
ArrayOfDateStrings = Split(ListOfDateStrings, Delimiter)
Dim OldestDate As Date
Dim DateString As Variant
For Each DateString In ArrayOfDateStrings
Dim NumericDate As Variant
NumericDate = ConvertStringToDate(DateString, DateFormat)
If Not IsError(NumericDate) Then
If CDate(NumericDate) < OldestDate Or OldestDate = 0 Then
OldestDate = CDate(NumericDate)
End If
Else
' Something went wrong
ExtractOldestDateFromStringList = NumericDate
Exit Function
End If
Next DateString
ExtractOldestDateFromStringList = OldestDate
End Function
Public Function ConvertStringToDate(ByVal DateString As String, ByVal DateFormat As String) As Variant
' returns #VALUE! if something is wrong with the DateString
' returns #N/A if the DateFormat is not supported
Dim Delimiter As String
If InStr(DateString, "/") Then
Delimiter = "/"
ElseIf InStr(DateString, ".") Then
Delimiter = "."
ElseIf InStr(DateString, " ") Then
Delimiter = " "
ElseIf InStr(DateString, "-") Then
Delimiter = "-"
Else
' no valid delimiter found
ConvertStringToDate = CVErr(xlErrValue)
Exit Function ' return #VALUE!
End If
' split into parts
Dim SplitString() As String
SplitString = Split(DateString, Delimiter)
Dim NumericDate As Date
' convert to numeric date
Select Case DateFormat
'day month year
Case "dd.mm.yyyy", "d.m.yyyy", "dd.mm.yy", "d.m.yy", "dd/mm/yyyy", "d/m/yyyy", "dd/mm/yy"
NumericDate = DateSerial(SplitString(2), SplitString(1), SplitString(0))
'month day year
Case "mm/dd/yyyy", "m/d/yyyy", "mm/dd/yy"
NumericDate = DateSerial(SplitString(2), SplitString(0), SplitString(1))
'year month day
Case "yyyy-mm-dd", "yyyy/m/d", "yyyy/mm/dd"
NumericDate = DateSerial(SplitString(0), SplitString(1), SplitString(2))
Case Else
ConvertStringToDate = CVErr(xlErrNA)
Exit Function ' return #N/A
End Select
' check conversion if it is a real date and matches the string
If Format$(NumericDate, Replace$(DateFormat, Delimiter, "\" & Delimiter)) = DateString Then
ConvertStringToDate = NumericDate
Else
ConvertStringToDate = CVErr(xlErrValue)
' return #VALUE!
End If
End Function
這可以用作如下公式:
=ExtractOldestDateFromStringList(A1,", ","dd.mm.yyyy")
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/487449.html
上一篇:使用列A中使用的引數名稱在excel中顯示使用的公式
下一篇:為什么使用這行代碼不起作用?
