Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1900to1904
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
VBA Fenster verändert Datum format
18.10.2022 11:42:59
Boris.S.
Hallo zusammen,
bei meiner Excel habe ich eine UF die vorgegebene Daten von der Tabelle 3 zieht, unter anderen die "Dauer" also bis wann es fertig sein soll, diese habe ich in der Spalte "Daten" in der Excel in Spalte A drin, und sieht so aus:
Mrz. 22
Feb. 22
Mai. 22 usw.
von ich die UF anklicke und die Dauer auswählen möchte Zeigt es aber immer 01.01.2022, 01.02.22 usw an.
Datumformat habe ich in beiden Exceltabellen richtig ausgewählt. Also denke ich es liegt am Code?
(achtung nicht verwechseln mit Datum, hier Trage ich nur ein wann ich es eingetragen habe).
Könnt ihr mir weiterhelfen?
Grüße Boris

Private Sub CB_Eintragen_Click()
Dim ws As Worksheet
Set ws = Worksheets("KVP")
Dim wsdaten As Worksheet
Set wsdaten = Worksheets("Daten")
Dim datum As String
Nachricht = 0
If Nachricht = 0 Then
Application.ScreenUpdating = False
anzahlzeile = ws.UsedRange.Rows.Count
tag1 = Left(TB_Datum.Value, 2)
monat1 = Mid(TB_Datum.Value, 4, 2)
jahr1 = Right(TB_Datum.Value, 4)
ws.Cells(anzahlzeile + 1, 2).Value = tag1 & "." & monat1 & "." & jahr1
ws.Cells(anzahlzeile + 1, 2).NumberFormat = "dd.mm.yyyy"
ws.Cells(anzahlzeile + 1, 3).Value = TB_Unternehmen.Value
ws.Cells(anzahlzeile + 1, 4).Value = TB_Bereich.Value
ws.Cells(anzahlzeile + 1, 5).Value = TB_Bereichsverantw.Value
ws.Cells(anzahlzeile + 1, 6).Value = TB_Dauer.Value
ws.Cells(anzahlzeile + 1, 7).Value = TB_Name.Value
ws.Cells(anzahlzeile + 1, 8).Value = TB_Problem.Value
ws.Cells(anzahlzeile + 1, 9).Value = TB_Maßnahme.Value 'Vorschlag / Maßnahme
ws.Cells(anzahlzeile + 1, 11).Value = TB_Verantwortlicher.Value
ws.Cells(anzahlzeile + 1, 12).Value = TB_Status.Value
For a = 2 To wsdaten.Cells(Rows.Count, 4).End(xlUp).Row
If TB_Bereich.Text = wsdaten.Cells(a, 2).Value Then
End If
Next a
ws.Rows(anzahlzeile + 1).EntireRow.AutoFit
For a = 1 To 15
ws.Cells(anzahlzeile + 1, a).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Next a
UF_NeuerEintrag.Hide
End If
Application.ScreenUpdating = True
End Sub

Private Sub Label2_Click()
End Sub

Private Sub Label20_Click()
End Sub

Private Sub Label7_Click()
End Sub
'

Private Sub Check_Click()
'If check.Value = True Then
'    TB_Name.Style = fmStyleDropDownCombo
'End If
'If check.Value = False Then
'    TB_Name.Style = fmStyleDropDownList
'End If
'End Sub

Private Sub TB_Bereich_Change()
Dim ws As Worksheet
Set ws = Worksheets("KVP")
Dim wsdaten As Worksheet
Set wsdaten = Worksheets("Daten")
For a = 2 To wsdaten.Cells(Rows.Count, 4).End(xlUp).Row
If TB_Bereich.Text = wsdaten.Cells(a, 2).Value Then
TB_Unternehmen.Value = wsdaten.Cells(a, 4).Value
TB_Bereichsverantw.Value = wsdaten.Cells(a, 3).Value
End If
Next
End Sub

Private Sub TB_Datum_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr("1234567890." & Chr$(8), Chr$(KeyAscii)) = 0 Then
KeyAscii = 0
End If
TB_Datum.MaxLength = 10
End Sub


Private Sub TB_Datum_AfterUpdate()
If TB_Datum.Value  "" Then
If Len(TB_Datum.Value)  10 Or Mid(TB_Datum.Value, 3, 1)  "." Or Mid(TB_Datum.Value, 6, 1)  "." Then
MsgBox "Bitte das Datum im Format 'DD.MM.JJJJ' eingeben"
TB_Datum.Value = ""
End If
End If
If TB_Datum.Value  "" Then
If Not IsDate(TB_Datum.Value) Then
MsgBox "Bitte ein gültiges Datum eingeben"
TB_Datum.Value = ""
End If
End If
End Sub

Private Sub TB_Dauer_Change()
If TB_Dauer.Value  "Boris" Then
TB_Maßnahme.Enabled = True
TB_Problem.Enabled = True
TB_Maßnahme.BackColor = &H80000005
TB_Problem.BackColor = &H80000005
TB_Status.Enabled = True
TB_Status.BackColor = &H80000005
TB_Verantwortlicher.Enabled = True
TB_Verantwortlicher.BackColor = &H80000005
Label12.Font.Bold = True
Label14.Font.Bold = True
Label8.Font.Bold = True
Label9.Font.Bold = True
End If
End Sub

Private Sub TB_Grund_Change()
End Sub

Private Sub TB_Name_Change()
End Sub

Private Sub TB_Problem_Change()
Länge = Len(TB_Problem.Value)
Label_Problem.Caption = 120 - Länge
End Sub

Private Sub TB_Maßnahme_Change()
Länge = Len(TB_Maßnahme.Value)
Label_Maßnahme.Caption = 120 - Länge
End Sub
Sub UserForm_Activate()
Application.ScreenUpdating = False
Dim ws As Worksheet
Set ws = Worksheets("KVP")
Dim wsdaten As Worksheet
Set wsdaten = Worksheets("Daten")
anzahlzeile = ws.UsedRange.Rows.Count
If Not IsNumeric(ws.Cells(anzahlzeile, 1)) Then
Nr = 1
TB_Nr.Caption = Nr
Else
Nr = ws.Cells(anzahlzeile, 1).Value
Nr = Nr + 1
End If
TB_Dauer.Clear
TB_Bereich.Clear
TB_Status.Clear
TB_Verantwortlicher.Clear
TB_Name.Clear
TB_Datum.Value = ""
TB_Unternehmen.Value = ""
TB_Bereich.Value = ""
TB_Bereichsverantw.Value = ""
TB_Dauer.Value = ""
TB_Name.Value = ""
TB_Problem.Value = ""
TB_Maßnahme.Value = ""
TB_Verantwortlicher.Value = ""
TB_Status.Value = ""
Label_Problem.Caption = "120"
Label_Maßnahme.Caption = "120"
For a = 2 To wsdaten.Cells(Rows.Count, 1).End(xlUp).Row
TB_Dauer.AddItem wsdaten.Cells(a, 1)
Next
For a = 2 To wsdaten.Cells(Rows.Count, 2).End(xlUp).Row
TB_Bereich.AddItem wsdaten.Cells(a, 2)
Next
For a = 2 To wsdaten.Cells(Rows.Count, 5).End(xlUp).Row
TB_Name.AddItem wsdaten.Cells(a, 5)
Next
For a = 2 To wsdaten.Cells(Rows.Count, 6).End(xlUp).Row
TB_Status.AddItem wsdaten.Cells(a, 6)
Next
For a = 2 To wsdaten.Cells(Rows.Count, 7).End(xlUp).Row
TB_Verantwortlicher.AddItem wsdaten.Cells(a, 7)
Next
Application.ScreenUpdating = True
End Sub

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: VBA Fenster verändert Datum format
18.10.2022 11:47:08
Der
Hallo,
warum schreibst Du das Datum als Text in die Zelle, wenn Du das ganze dann als Datum formatierst?
Statt:

tag1 = Left(TB_Datum.Value, 2)
monat1 = Mid(TB_Datum.Value, 4, 2)
jahr1 = Right(TB_Datum.Value, 4)
ws.Cells(anzahlzeile + 1, 2).Value = tag1 & "." & monat1 & "." & jahr1
Kannst Du doch das Datum direkt reinschreiben:

ws.Cells(anzahlzeile + 1, 2).Value = cdate(TB_Datum.Value)

AW: VBA Fenster verändert Datum format
18.10.2022 12:48:09
Boris.S.
Das war eben das Datum das ich manuell eintrage, das war ok so.
ich meine es liegt hier dran?
For a = 2 To wsdaten.Cells(Rows.Count, 1).End(xlUp).Row
TB_Dauer.AddItem wsdaten.Cells(a, 1)
Anzeige
AW: VBA Fenster verändert Datum format
18.10.2022 12:53:13
Daniel
Hi
probier mal folgendes, um deine Box zu befüllen:

TB_Dauer.RowSource = "'" & wsdaten.name & "'!A2:A" & wsdaten.Cells(Rows.Count, 1).End(xlUp).Row
Gruß Daniel
AW: VBA Fenster verändert Datum format
18.10.2022 13:02:05
Boris.S.
Fast perfekt, wenn ich es auswähle zeigt es richtig an, wenn ich es aber anklicke steht aber 44835 drin, wenn ich es dann bestätige steht es in der Excel richtig.
Woran liegt das mit der 44835?
AW: VBA Fenster verändert Datum format
18.10.2022 13:39:55
Daniel
Hi
für Excel ist ein Datum eine normale Zahl. Die Zählung beginnt am 1.1.1900 mit 1.
44835 ist der unformatierte Zahlenwert des Datums.
(kannst du auch prüfen, in dem du für eine Zelle mit Datum das Zahlenformat Standard einstellst).
Gruß Daniel
Anzeige

312 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige