10.12.2018, 23:52
Guten Abend Cadmus,
ja es gibt wohl einige Datumselemente wo man nicht weiß was sie bedeuten sollen - so wie Du es beschrieben hast.
Vielleicht gibt es noch eine Idee?
Ich habe trotzdem mal versucht was zu basteln. Kuckst Du:
Tabelle2
Zellen mit Format Standard werden nicht dargestellt
Hier der Code:
ja es gibt wohl einige Datumselemente wo man nicht weiß was sie bedeuten sollen - so wie Du es beschrieben hast.
Vielleicht gibt es noch eine Idee?
Ich habe trotzdem mal versucht was zu basteln. Kuckst Du:
Tabelle2
A | B | C | |
1 | Stellen | Original | Formatiert |
2 | 7 | 1112019 | '11.1.2019 |
3 | 7 | 1122019 | '11.2.2019 |
4 | 7 | 2632018 | '26.3.2018 |
5 | 7 | 2252018 | '22.5.2018 |
6 | 7 | 2672018 | '26.7.2018 |
7 | 6 | 112018 | '1.1.2018 |
8 | 7 | 3102018 | '3.10.2018 |
9 | 8 | 18112018 | 18.11.2018 |
10 | 8 | 25112018 | 25.11.2018 |
11 | 7 | 2122018 | '21.2.2018 |
12 | 7 | 9122018 | '9.12.2018 |
13 | 8 | 16122018 | 16.12.2018 |
Zahlenformate | |||
Zelle | Format | Inhalt | |
C9 | 'TT.MM.JJJJ | 43422 | |
C10 | 'TT.MM.JJJJ | 43429 | |
C13 | 'TT.MM.JJJJ | 43450 |
http://excel-inn.de/dateien/vba_beispiel..._addin.zip |
http://Hajo-Excel.de/tools.htm |
XHTML-Tabelle zur Darstellung in Foren, einschl. der neuen Funktionen ab Version 2007 |
Add-In-Version 25.15 einschl. 64 Bit |
Hier der Code:
Code:
Sub Datum_Umwandeln()
For lngRow = 2 To Cells(Rows.Count, 3).End(xlUp).Row
If (Len(Cells(lngRow, 3)) = 8 Or Len(Cells(lngRow, 3)) = 7 Or Len(Cells(lngRow, 3)) = 6) And IsNumeric(Cells(lngRow, 3)) Then
If Len(Cells(lngRow, 3)) = 8 Then
Cells(lngRow, 3).Value = CDate(Mid(Cells(lngRow, 3), 1, 2) & "." & Mid(Cells(lngRow, 3), 3, 2) & "." & Mid(Cells(lngRow, 3), 5, 4))
ElseIf Len(Cells(lngRow, 3)) = 7 And IsNumeric(Cells(lngRow, 3)) Then
strFull = Cells(lngRow, 3)
strZahl = Left(strFull, 2)
If strZahl >= 31 And Mid(Cells(lngRow, 3), 2, 2) <= 12 Then '0 Or Mid(Z, 3, 2) > 12 Then
Cells(lngRow, 3).Value = CSting2date(Cells(lngRow, 3))
Cells(lngRow, 1).Interior.ColorIndex = 35 ' lindgrün
Cells(lngRow, 3).Interior.ColorIndex = 35 ' lindgrün
ElseIf Mid(Cells(lngRow, 3), 3, 1) = 0 And Left(Cells(lngRow, 3), 1) <= 9 Then
Cells(lngRow, 3).Interior.ColorIndex = 3 ' rot
Cells(lngRow, 3).Value = CSting2date(Cells(lngRow, 3))
Else
Cells(lngRow, 3).Value = CSting1date(Cells(lngRow, 3))
Cells(lngRow, 1).Interior.ColorIndex = 44 ' orange
Cells(lngRow, 3).Interior.ColorIndex = 44 ' orange
End If
Else
Cells(lngRow, 3).Value = CSting1date(Cells(lngRow, 3))
End If
Else
Cells(lngRow, 3).Value = CDate(Mid(Cells(lngRow, 3), 1, 1) & "." & Mid(Cells(lngRow, 3), 2, 1) & "." & Mid(Cells(lngRow, 3), 3, 4))
End If
Next lngRow
End Sub
'Wenn Datum 7-stellig, links <= 31, Mid <=12
Function CSting1date(s As String) As String
Dim t As String
t = "." & Right(s, 4)
s = Left(s, Len(s) - 4)
t = "." & Right(s, 1) & t
s = Left(s, Len(s) - 1)
CSting1date = s & t
'Z = CSting1date
End Function
'Wenn Datum 7-stellig, links >= 31, Mid <=12
Function CSting2date(s As String) As String
Dim t As String
t = "." & Right(s, 4)
s = Left(s, Len(s) - 4)
t = "." & Right(s, 2) & t
s = Left(s, Len(s) - 2)
CSting2date = s & t
'Z = CSting2date
End Function