Ich habe eine UseForm mit einer Multipage in der sich 10 Pages befinden.
Diese sind benannt mit "pg_1" bis "pg_10".
Ich möchte die Caption - also den angezeigten Namen - beim Initialisieren festlegen.
Das funktioniert gut, wenn ich einen langen Code schreibe und jede Page einzeln anspreche.
Ich möchte den Code aber kürzen und mit einer Schleife arbeiten.
Dazu verwende ich "Controls", bekomme aber die Fehlermeldung "LZF 438 Objekt unterstützt diese Eigenschaft oder Methode nicht".
Weiß jemand was ich falsch mache?
Vielen Dank für eure Hilfe, bin echt ratlos!
Kurzer Codeversuch:
With UserForm_Gruppeneinteilung.Frame_Gruppenzuordnung.MultiPage_1_1
Dim H As Byte
Dim I As Integer
H = 1
For I = 1 To 100 Step 10
If Sheets("Rohdaten").Cells(I + 10, 1).Value "" Then
.Controls("pg_" & H).Caption = Sheets("Rohdaten").Cells(I + 1, 1).Value & "-" & Sheets("Rohdaten").Cells(I + 10, 1).Value
Else
.Controls("pg_" & H).Caption = Sheets("Rohdaten").Cells(I + 1, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
H = H + 1
Next I
End With
Langer Code:
With UserForm_Gruppeneinteilung.Frame_Gruppenzuordnung.MultiPage_1_1
If Sheets("Rohdaten").Cells(11, 1).Value "" Then
.pg_1.Caption = Sheets("Rohdaten").Cells(2, 1).Value & "-" & Sheets("Rohdaten").Cells(11, 1).Value
Else
.pg_1.Caption = Sheets("Rohdaten").Cells(2, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
If Sheets("Rohdaten").Cells(21, 1).Value "" Then
.pg_2.Caption = Sheets("Rohdaten").Cells(12, 1).Value & "-" & Sheets("Rohdaten").Cells(21, 1).Value
Else
.pg_2.Caption = Sheets("Rohdaten").Cells(12, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
If Sheets("Rohdaten").Cells(31, 1).Value "" Then
.pg_3.Caption = Sheets("Rohdaten").Cells(22, 1).Value & "-" & Sheets("Rohdaten").Cells(31, 1).Value
Else
.pg_3.Caption = Sheets("Rohdaten").Cells(22, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
If Sheets("Rohdaten").Cells(41, 1).Value "" Then
.pg_4.Caption = Sheets("Rohdaten").Cells(32, 1).Value & "-" & Sheets("Rohdaten").Cells(41, 1).Value
Else
.pg_4.Caption = Sheets("Rohdaten").Cells(32, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
If Sheets("Rohdaten").Cells(51, 1).Value "" Then
.pg_5.Caption = Sheets("Rohdaten").Cells(42, 1).Value & "-" & Sheets("Rohdaten").Cells(51, 1).Value
Else
.pg_5.Caption = Sheets("Rohdaten").Cells(42, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
If Sheets("Rohdaten").Cells(61, 1).Value "" Then
.pg_6.Caption = Sheets("Rohdaten").Cells(52, 1).Value & "-" & Sheets("Rohdaten").Cells(61, 1).Value
Else
.pg_6.Caption = Sheets("Rohdaten").Cells(52, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
If Sheets("Rohdaten").Cells(71, 1).Value "" Then
.pg_7.Caption = Sheets("Rohdaten").Cells(62, 1).Value & "-" & Sheets("Rohdaten").Cells(71, 1).Value
Else
.pg_7.Caption = Sheets("Rohdaten").Cells(62, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
If Sheets("Rohdaten").Cells(81, 1).Value "" Then
.pg_8.Caption = Sheets("Rohdaten").Cells(72, 1).Value & "-" & Sheets("Rohdaten").Cells(81, 1).Value
Else
.pg_8.Caption = Sheets("Rohdaten").Cells(72, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
If Sheets("Rohdaten").Cells(91, 1).Value "" Then
.pg_9.Caption = Sheets("Rohdaten").Cells(82, 1).Value & "-" & Sheets("Rohdaten").Cells(91, 1).Value
Else
.pg_9.Caption = Sheets("Rohdaten").Cells(82, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
If Sheets("Rohdaten").Cells(101, 1).Value "" Then
.pg_10.Caption = Sheets("Rohdaten").Cells(92, 1).Value & "-" & Sheets("Rohdaten").Cells(101, 1).Value
Else
.pg_10.Caption = Sheets("Rohdaten").Cells(92, 1).Value & "-" & Sheets("Rohdaten").Cells(letzteZeile, 1).Value
End If
End With