Clever-Excel-Forum

Normale Version: VBA Userform - mehrere Fragen
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hallo liebe Excelfreunde,

ich benötige mal wieder etwas Hilfe von euch in Sachen VBA.
Aktuell habe ich mehrere Baustellen.

Ich habe ein UserForm erstellt mit 6 Textboxen, 1 ComboBox, 2 Optionsgruppenfeldern mit je 2 Optionen (ja/nein) und einem Button.

1. Ausgabe von Optionsgruppenfeld an bestimmte Zelle

Ich möchte, dass die Auswahl der Optionsgruppe1 (besteht aus Option1Ja & Option1Nein) in die Zelle AC3 ausgegeben wird
und die Optionsgruppe2 (besteht aus Option2Ja & Option2Nein) in die Zelle S7.

Mein Code, um die Werte für die Textboxen und ComboBox zu übertragen funkioniert und sieht so aus:
Code:
Private Sub CmdButtonFertig_Click()

Range("S2").Value = TextBox1.Value
Range("S3").Value = ComboBox1.Value
Range("S4").Value = TextBox2.Value
Range("S5").Value = TextBox3.Value
Range("S6").Value = TextBox4.Value
Range("AB7").Value = TextBox5.Value
Range("S8").Value = TextBox6.Value

End Sub

Wie kann ich die anderen Dinge mit einbinden?

2. Textbox inaktiv setzen und bei Aktivierung von Option aktivieren

TextBox5 habe ich in den Einstellungen auf Visible = False gestellt. Die Textbox soll nur eingeblendet werden,
wenn in der Optionsgruppe2 die Option2Ja aktiviert wurde.

3. Button nur aktivieren wenn 4-5 TextBoxen befüllt wurden

Den CmdButtonFertig habe ich ebenfalls in den Einstellungen auf Visible = False gestellt.
Dieser soll nun aktiviert werden, wenn:
- TextBox1 bis TextBox4 befüllt sind (teils mit Text und teils mit Zahlen),
- aus der ComboBox1 ein Wert gewählt wurde,
- in beiden Optionsgruppen eine Option gewählt wurde und
- wenn bei Optionsgruppe2 die Option2Ja gewählt wurde auch TextBox5 befüllt ist

*die TextBox6 kann außer Acht gelassen werden, da diese grundsätzlich Optional zu befüllen ist

Ich hoffe, das ist Verständlich und Ihr könnt helfen.
Vielen Dank vorab. :19:
Hallo,

die Chancen auf Hilfe vergrößern sich sicher erheblich, wenn du hier eine Beispieldatei hochlädst. Dann braucht niemand das UserForm nachbauen.
Gerne, hier die Beispieldatei:

[attachment=25457]

Noch zur Info der Button "Formular öffnen" fliegt später raus, da das Formular gleich beim öffnen der Datei mit auf geht.

EDIT:

mein Problem Nr 1. habe ich gelöst bekommen mit folgendem Code:

Code:
Private Sub CmdButtonFertig_Click()

Range("S2").Value = TextBox1.Value
Range("S3").Value = ComboBox1.Value
Range("S4").Value = TextBox2.Value
Range("S5").Value = TextBox3.Value
Range("S6").Value = TextBox4.Value
Range("AB7").Value = TextBox5.Value
Range("S8").Value = TextBox6.Value

If Option1Ja = True Then
Range("AC3") = Option1Ja.Caption
ElseIf Option1Nein = True Then
Range("AC3") = Option1Nein.Caption
End If

If Option2Ja = True Then
Range("S7") = Option2Ja.Caption
ElseIf Option2Nein = True Then
Range("S7") = Option2Nein.Caption
End If

End Sub


Nun benötige ich noch Hilfe bei 2. und 3. oder gibt es für 1. eine optimalere Lösung?
Hallo

ich biete mal die überarbeitete Test Datei als Lösungsmöglichkeit an. Ob meine Idee zur 1. Frage besser ist weiss ich nicht?
Mein Makro löscht nach der Eingabe des Button "Fertig" wieder alle TextBoxen, und setzt die ComboBox auf Null zurück.

mfg  Gast 123
Hallo,

das wäre mein Vorschlag für 1 bis 3:

Option Explicit

Private Sub CmdButtonFertig_Click()
Range("S2").Value = TextBox1.Value
Range("S3").Value = ComboBox1.Value
Range("S4").Value = TextBox2.Value
Range("S5").Value = TextBox3.Value
Range("S6").Value = TextBox4.Value
Range("AB7").Value = TextBox5.Value
Range("S8").Value = TextBox6.Value
End Sub

Private Sub ComboBox1_Change()
CmdButtonFertig.Visible = (ComboBox1.ListIndex > -1) * Len(TextBox1) * Len(TextBox2) * Len(TextBox3) * Len(TextBox4) * (Option2Nein - Len(TextBox5))
End Sub

Private Sub Option1Ja_Change()
Range("AC3") = Choose(Abs(Option1Ja) + 1, "Nein", "Ja")
CmdButtonFertig.Visible = (ComboBox1.ListIndex > -1) * Len(TextBox1) * Len(TextBox2) * Len(TextBox3) * Len(TextBox4) * (Option2Nein - Len(TextBox5))
End Sub

Private Sub Option2Ja_Change()
Range("S7") = Choose(Abs(Option2Ja) + 1, "Nein", "Ja")
TextBox5.Visible = Option2Ja.Value
If Option2Nein Then TextBox5 = ""
CmdButtonFertig.Visible = (ComboBox1.ListIndex > -1) * Len(TextBox1) * Len(TextBox2) * Len(TextBox3) * Len(TextBox4) * (Option2Nein - Len(TextBox5))
End Sub

Private Sub TextBox1_Change()
CmdButtonFertig.Visible = (ComboBox1.ListIndex > -1) * Len(TextBox1) * Len(TextBox2) * Len(TextBox3) * Len(TextBox4) * (Option2Nein - Len(TextBox5))
End Sub

Private Sub TextBox2_Change()
CmdButtonFertig.Visible = (ComboBox1.ListIndex > -1) * Len(TextBox1) * Len(TextBox2) * Len(TextBox3) * Len(TextBox4) * (Option2Nein - Len(TextBox5))
End Sub

Private Sub TextBox3_Change()
CmdButtonFertig.Visible = (ComboBox1.ListIndex > -1) * Len(TextBox1) * Len(TextBox2) * Len(TextBox3) * Len(TextBox4) * (Option2Nein - Len(TextBox5))
End Sub

Private Sub TextBox4_Change()
CmdButtonFertig.Visible = (ComboBox1.ListIndex > -1) * Len(TextBox1) * Len(TextBox2) * Len(TextBox3) * Len(TextBox4) * (Option2Nein - Len(TextBox5))
End Sub

Private Sub TextBox5_Change()
CmdButtonFertig.Visible = (ComboBox1.ListIndex > -1) * Len(TextBox1) * Len(TextBox2) * Len(TextBox3) * Len(TextBox4) * (Option2Nein - Len(TextBox5))
End Sub

Private Sub UserForm_Initialize()
' Die Daten werden im Code Zeilenweise eingetragen
With Me.ComboBox1
.AddItem "IB 1"
.AddItem "IB 2"
.AddItem "IB 3"
.AddItem "IB 4"
.AddItem "IB 5"
.AddItem "IB 6"
.AddItem "IB 7"
.AddItem "IB 8"
.AddItem "IB 9"
.AddItem "IB 10"
.AddItem "IB 11"
End With
End Sub

Code eingefügt mit: Excel Code Jeanie

Gruß Uwe
PHP-Code:
Private Sub CmdButtonFertig_Click()
 
 Range("S2").resize(,7).Value = array(TextBox1,ComboBox1TextBox2,TextBox3TextBox4,"",TextBox6)
  Range("AB7").Value TextBox5
End Sub 

und
PHP-Code:
Private Sub Userform_initialize()
  
Combobox1.List=[index("IB "&row(1:11),)]
End Sub 
Hallo,

ganz lieben Dank für die guten Vorschläge und eure Hilfe, jetzt geht alles :17: .
Hallo,

jetzt sollte es zuverlässig klappen:

Code:
Option Explicit

Private Sub CmdButtonFertig_Click()
 Range("S2").Value = TextBox1.Value
 Range("S3").Value = ComboBox1.Value
 Range("S4").Value = TextBox2.Value
 Range("S5").Value = TextBox3.Value
 Range("S6").Value = TextBox4.Value
 Range("AB7").Value = TextBox5.Value
 Range("S8").Value = TextBox6.Value
End Sub

Private Sub ComboBox1_Change()
 CmdButtonFertigVisible
End Sub

Private Sub Option1Ja_Change()
 Range("AC3") = Choose(Abs(Option1Ja) + 1, "Nein", "Ja")
 CmdButtonFertigVisible
End Sub

Private Sub Option1Nein_Change()
 CmdButtonFertigVisible
End Sub

Private Sub Option2Ja_Change()
 Range("S7") = Choose(Abs(Option2Ja) + 1, "Nein", "Ja")
 TextBox5.Visible = Option2Ja.Value
 If Option2Nein Then TextBox5 = ""
 CmdButtonFertigVisible
End Sub

Private Sub Option2Nein_Change()
 CmdButtonFertigVisible
End Sub

Private Sub TextBox1_Change()
 CmdButtonFertigVisible
End Sub

Private Sub TextBox2_Change()
 CmdButtonFertigVisible
End Sub

Private Sub TextBox3_Change()
 CmdButtonFertigVisible
End Sub

Private Sub TextBox4_Change()
 CmdButtonFertigVisible
End Sub

Private Sub TextBox5_Change()
 CmdButtonFertigVisible
End Sub

Private Sub CmdButtonFertigVisible()
 CmdButtonFertig.Visible = (ComboBox1.ListIndex > -1) * (Option2Nein - Len(TextBox5)) * _
                           (Option1Ja + Option1Nein) * (Option2Ja + Option2Nein) * _
                           Len(TextBox1) * Len(TextBox2) * Len(TextBox3) * Len(TextBox4)
End Sub

Private Sub UserForm_Initialize()
    ' Die Daten werden im Code Zeilenweise eingetragen
   With Me.ComboBox1
       .AddItem "IB 1"
       .AddItem "IB 2"
       .AddItem "IB 3"
       .AddItem "IB 4"
       .AddItem "IB 5"
       .AddItem "IB 6"
       .AddItem "IB 7"
       .AddItem "IB 8"
       .AddItem "IB 9"
       .AddItem "IB 10"
       .AddItem "IB 11"
   End With
End Sub

Gruß Uwe