ich komme mal wieder nicht weiter und bitte um eure Hilfe.
Ich habe ein UserForm mit dessen Hilfe ich Werte aus Textboxen in ein Datenblatt eintrage. Die Textboxen werden händisch befüllt. Dieser Teil funktioniert, Dank diese super Forums, schon.
Eine 2. Möglichkeit soll darin bestehen die Daten aus einem bestimmten Blatt, per Combobox-Auswahl, in die Textfelder einzulesen. Ich habe einen Code aus einem anderem Projekt übernommen. Es funktioniert aber nicht und ich weiß nicht was geändert werden muss.
Nachfolgend habe ich mal den gesamten Code eingefügt (zur Übersicht). Was nicht funktioniert _ sind aber die ersten beiden Abschnitte: "
Private Sub CommandButton1_Click()" und "
Private Sub ComboBox_RechnAusw_Change()"
Danke fürs lesen und die Hilfe
mfg, Andreas
Option Explicit
Private wks As Worksheet
Private bolAktion As Boolean 'Merker, dass eine Aktion bereits ausgeführt wird
Private Sub CommandButton1_Click()
Dim wks As Worksheet
Worksheets("EinAusgangsRech").Visible = True
Worksheets("EinAusgangsRech").Activate
If bolAktion = True Then Exit Sub
bolAktion = True
ComboBox_RechnAusw.Clear
Call EinAusblenden
With ComboBox_RechnAusw
.ColumnCount = 2
.ColumnWidths = ";0"
For a = 8 To 200
Select Case a
Case 8 To 200
If wks.Rows(a).RowHeight > 0 Then
.AddItem
.List(.ListCount - 1, 0) = wks.Cells(a, 1) & " - " & wks.Cells(a, 2)
.List(.ListCount - 1, 1) = a
End If
End Select
Next a
End With
bolAktion = False
End Sub
Private Sub ComboBox_RechnAusw_Change()
If ComboBox_RechnAusw "" Then
a = ComboBox_RechnAusw.Column(1)
With ActiveSheet
TextBoxB_AR.Text = Cells(a, 5).Text
TextBoxDatenAR.Text = Cells(a, 3).Text
TextBoxVorgang.Text = Cells(a, 4).Text
TextBox1.Text = Cells(a, 7).Text
End With
End If
End Sub
Private Sub UserForm_Initialize()
Dim ws As Worksheet
With Me.ComboBox_BuchungsdatumAR
.RowSource = "Buchungsdatum"
ComboBox_BuchungsdatumAR.Value = Date
End With
With Me.ComboBox_DatenAR
.RowSource = "Buchungsdaten"
.ListIndex = -1
End With
With Me.ComboBox_VorgangAR
.RowSource = "Buchungsvorgang"
.ListIndex = -1
End With
End Sub
Private Sub UserForm_Activate()
Me.TextBoxB_AR.Text = "0.00" 'gibt 0,00 aus
Me.TextBoxSummeAR.Text = "0,00"
Me.TextBox1.Text = "0,00"
End Sub
Private Sub CommandButtonAR_Click()
Dim lngzeile As Long
lngzeile = Cells(5, 1).End(xlDown).Row + 1
Dim iAntwort As Integer
ActiveSheet.Unprotect
Application.ScreenUpdating = False
Application.DisplayAlerts = False
' Abfrage ob Pflichtfelder gefüllt sind
If ComboBox_BuchungsdatumAR.ListIndex = -1 Or TextBoxB_AR.Value = 0 Or ComboBox_DatenAR. _
Text = "" Or ComboBox_VorgangAR.Text = "" Then
MsgBox "Bitte alle Pflichtfelder * füllen!", vbInformation, "Achtung"
TextBoxleerAR.SetFocus
Else
' Abfrage ob Buchungswert ungleich Summenwert
If CDbl(TextBoxB_AR.Value) CDbl(TextBoxSummeAR.Value) Then
MsgBox "Der Rechnungsbetrag stimmt nicht mit der Summe der Kontobuchnungen überein!", _
vbInformation, "Achtung"
TextBoxleerAR.SetFocus
Else
'Abfrage ob Buchungswert nicht im plus
If TextBoxB_AR.Value
Function TrageWerteEin(ByVal lngzeile As Long)
Cells(lngzeile, 1).Value = ComboBox_BuchungsdatumAR.Value
Cells(lngzeile, 5).Value = TextBoxB_AR.Value * 1
Cells(lngzeile, 3).Value = ComboBox_DatenAR.Value
Cells(lngzeile, 4).Value = ComboBox_VorgangAR.Value
Cells(lngzeile, 7).Value = TextBox1.Value * 1
End Function
Private Sub ComboBox_BuchungsdatumAR_Change() 'Datum der Buchung
Dim strJahr As String, wks As Worksheet
Dim iFehler As Integer
On Error GoTo Fehler
ComboBox_BuchungsdatumAR.Value = Format(ComboBox_BuchungsdatumAR.Value, ("dd.mm.yyyy"))
strJahr = Right(ComboBox_BuchungsdatumAR.Value, 4)
iFehler = 1
Set wks = ThisWorkbook.Worksheets("EinnAusg " & strJahr)
wks.Activate
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'gewähltes Blatt sichtbar, aktivieren, Blattschutz aufheben
wks.Visible = True
wks.Activate
wks.Unprotect
'Andere Blätter ausblenden
For Each wks In ThisWorkbook.Worksheets
If wks.Name Like "EinnAusg *" And InStr(wks.Name, strJahr) = 0 Then
wks.Protect
wks.Visible = xlSheetHidden
End If
Next
Resume01:
Fehler:
With Err
Select Case .Number
Case 0 'alles OK
Case 9
Select Case iFehler
Case 1
MsgBox "Blatt ""EinnAusg " & strJahr & """ existiert nicht"
Resume Resume01:
End Select
Case Else
MsgBox "Fehler-Nr.: " & .Number & vbLf & .Description
End Select
End With
End Sub
Private Sub TextBoxB_AR_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57, 8, 44, 45
Case Else
KeyAscii = 0
MsgBox "Es sind nur Ziffern, Komma und Minus zulässig!", vbInformation, "Hinweis"
End Select
End Sub
Private Sub TextBoxB_AR_AfterUpdate()
If TextBoxB_AR = Empty Then TextBoxB_AR = 0
TextBoxB_AR = Format(CDbl(TextBoxB_AR.Text), "#,##0.00")
End Sub
'##### Summen ######
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
SummeTextboxenAR
End Sub