AW: Mehrere Werte in einer Zelle auswerten
01.02.2018 11:24:44
Peter(silie)
Hallo,
per Formel weiß ich nicht ob das geht...
Habe aber eine VBA Lösung.
Einfach ein Modul erstellen und den unten stehenden Code einfügen.
Der Aufruf in der Tabelle sieht z.B. so aus: =MostFrequentDate(A1;15)
Der erste Parameter ist die Zelle mit den Datumswerten, der zweite ist Optional und
stellt die Anzahl der Monate dar, die hinzugefügt werden sollen.
Hier Beispiel Mappe: https://www.herber.de/bbs/user/119459.xlsm
Hier Code:
Function MostFrequentDate(ByRef Target As Range, Optional ByVal MonthsToAdd As Long = 0) As _
String
Dim i As Long, tmp As Date
Dim patter_ As String, value_ As String
Dim rx As Object, matches As Object
'Date pattern
pattern_ = "\d{2}.\d{2}.\d{4}"
'Define the value to look in
If Target.Rows.Count > 1 Then
value_ = Join(Application.Transpose(Target.Value), "")
ElseIf Target.Columns.Count > 1 Then
value_ = Join(Application.Transpose(Application.Transpose(Target.Value)), "")
Else
value_ = Target.Value
End If
'Create a Regexp Object
Set rx = CreateObject("vbscript.regexp")
With rx
.Global = True
.IgnoreCase = True
.MultiLine = False
.Pattern = pattern_
'Get all matches
Set matches = .Execute(value_)
End With
'If he found something
If matches.Count > 0 Then
'check for biggest Date
For i = 0 To matches.Count - 1
If CDate(matches(i)) > tmp Then
tmp = CDate(matches(i))
End If
Next i
'Add the amount of months
MostFrequentDate = CStr(DateAdd("m", MonthsToAdd, tmp))
Else
'if he found nothing
MostFrequentDate = "NoDateFound"
End If
End Function