AW: Textbox abhängig von Checkbox füllen?
21.11.2016 07:54:33
Checkbox
Hallo,
ok, um mal auf Hajos Grundgedanken aufzubauen , füg noch zu Deinen angegebenen Controls einen Übernehmen-Button (im Code Cmd-Button1) und einen Refresh-Button für die Checkboxen (Cmd-Button2) hinzu, ob jetzt diese kryptischen Abk-Texte in den Zellen so sinnvoll sind, müsstest Du vielleicht selbst nochmal überdenken:
' **********************************************************************
' Modul: UserForm1 Typ: Userform
' **********************************************************************
Option Explicit
Private mcolCheckBoxes As Collection
Private Sub CommandButton1_Click()
Dim objCheckBox As MSForms.CheckBox
For Each objCheckBox In mcolCheckBoxes
If objCheckBox.Value Then Exit For
Next
If Not objCheckBox Is Nothing And _
TextBox1.Text <> vbNullString And _
ComboBox1.Text <> vbNullString Then
Call prcFillInData(probjUserForm:=Me)
Set objCheckBox = Nothing
Else
Call MsgBox("Bitte tragen Sie alle erforderlichen Daten ein..", vbExclamation)
End If
End Sub
Private Sub CommandButton2_Click()
Dim objCheckBox As MSForms.CheckBox
For Each objCheckBox In mcolCheckBoxes
objCheckBox.Value = False
Next
End Sub
Private Sub UserForm_Activate()
Call Init_Class
ComboBox1.List() = Array("Montag", "Dienstag", "Mittwoch", _
"Donnerstag", "Freitag", "Samstag", "Sonntag")
End Sub
Private Sub UserForm_Terminate()
Set mcolCheckBoxes = Nothing
End Sub
Private Sub Init_Class()
Dim objControl As Control
Set mcolCheckBoxes = New Collection
For Each objControl In Controls
If TypeOf objControl Is MSForms.CheckBox Then
Call mcolCheckBoxes.Add(Item:=objControl)
End If
Next
End Sub
Public Property Get prpcolCheckBoxes() As Collection
Set prpcolCheckBoxes = mcolCheckBoxes
End Property
' **********************************************************************
' Modul: Modul1 Typ: Standardmodul
' **********************************************************************
Option Explicit
Option Private Module
Private lstrText As String
Private Sub prcConcatenate(ByRef probjUserForm As Object)
Dim objCheckBox As MSForms.CheckBox
Dim strText As String
Dim lngIndex As Long
lstrText = vbNullString
For Each objCheckBox In probjUserForm.prpcolCheckBoxes
With objCheckBox
If .Value Then
Select Case .Caption '// hier paßt Du Deine individuelle Abk._Länge an...
Case Is = "Schnitzel": lngIndex = 5
Case Is = "Erdbeerpudding": lngIndex = 4
Case Is = "Dessert", Is = "RoteGrütze", _
Is = "Sahnetorte": lngIndex = 3
Case Else: lngIndex = 2
End Select
lstrText = lstrText & Left$(String:=.Caption, Length:=lngIndex)
End If
End With
Next
End Sub
Public Sub prcFillInData(ByRef probjUserForm As Object)
Dim strText As String
Dim lngIndex As Long, lngLastRow As Long
Call prcConcatenate(probjUserForm:=probjUserForm)
With Tabelle1
If Not IsEmpty(.Cells(1, 1).Value) Then lngIndex = 1
lngLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
.Cells(lngLastRow + lngIndex, 1).Value = probjUserForm.TextBox1.Text
.Cells(lngLastRow + lngIndex, 2).Value = probjUserForm.ComboBox1.Text
.Cells(lngLastRow + lngIndex, 3).Value = lstrText
End With
End Sub
VBA/HTML - CodeConverter für Office-Foren
AddIn für Excel/Word 2000-2010 - komplett in VBA geschrieben von Lukas Mosimann
Projektbetreuung durch mumpel
Code erstellt und getestet in Office 14
Gruß, Mullit