Supportnet / Forum / Tabellenkalkulation
Steuerelement variabel adressieren?
Frage
Hallo
Ich möchte die Inhalte von 4 Textboxen auf der Userform mittels einer For .. Next Schleife ins ExcelSheet übertragen.
Leider mache ich einen Denkfehler und hoffe mir kann jemand helfen.
- So hab ich´s gedacht:
Option Explicit
Dim i As Variant
Dim tb As Object
Private Sub CommandButton1_Click()
i = 0
For i = 1 To 4
tb = "TextBox" & i ´<-----Hier ist der Fehler
Debug.Print tb
Cells(i, 2) = tb.Text
Next
End Sub
- aber bekomme Laufzeitfehler 91.
Danke vorab
Antwort 1 von Nepumuk
Hi,
so:
Gruß
Nepumuk
so:
Option Explicit
Private Sub CommandButton1_Click()
Dim intIndex As Integer
Dim txtMyBox As MSForms.TextBox
For intIndex = 1 To 4
Cells(intIndex, 2).Value = _
Controls("TextBox" & CStr(intIndex)).Text
Next
End Sub
Gruß
Nepumuk
Antwort 2 von vbNewbie
Hallo
erstmal Danke für die schnelle Antwort.
Es kommt damit kein Fehler mehr, aber es tut sich auch nichts.
Könntest Du mir erklären wofür hier "txtMxBox" und "Controls" steht ??
Gruß Norbert
erstmal Danke für die schnelle Antwort.
Es kommt damit kein Fehler mehr, aber es tut sich auch nichts.
Könntest Du mir erklären wofür hier "txtMxBox" und "Controls" steht ??
Gruß Norbert