Zellenwerte in Uerform übergeben!
10.05.2008 20:16:00
Gernot
Ich werd noch bald Wahnsinnig mit Excel 2003.
Ich lese aus einer Tabelle die Zellen in ein Userform ein, die vorher durch eine Suchroutine nach einem Schlüsselwort (hier Aktenzeichen) gefunden worden sind.
Die Tabelle (hier Forderungen) besteht aus 38 Spalten. Ich lese diese Spalten in die Textboxen rein.
Jetzt kommt der Fehler:
Er zeigt nur die Textboxen bis Spalte 26 an, was danach kommt "schneidet" er ab. Also Textboxen mit "tb35" sind dann leer. Wenn ich aber vorher eine MSgbox mit den Zelleninhalt (ZeileX, 38) anzeigen lasse, zeigt er den richtigen Wert an.
Wenn ich dann irgendwas an den Userform gemacht habe (zum Beispiel die verborgenen Textboxen (hier TB33) wieder sichtbar mache, dann zeigt er bis zum Neustart von Excel alle Felder richtig an.
Woran liegt das? Kann Excel nur bestimmte Anzahl von Spalten einlesen oder habe ich irgendwo einen Fehler im Userform drinn?
Hier der Code von der Userform:
(Der Bereich Forderungen ist dort der Fehler)
Private Sub userform_initialize()
ta2.List = Listenfelder.Range("Kategorie").Value
tb1.List = Forderungen.Range("RangeHauptgläubiger").Value
tb21.List = Listenfelder.Range("Grundlage").Value
tb7.List = Listenfelder.Range("Titelart").Value
tb4.List = Listenfelder.Range("Schuldner").Value
tb30.List = Listenfelder.Range("Forderungsstatus").Value
'label1.Caption = Now()
tb9 = Format("currency")
tb10 = Format("currency")
lb103.ColumnWidths = "55;60;54;130;43"
Gesamtschuld = 0
Restschuld = 0
' ---- Frame Vorgang ausblenden
Frame2.Visible = False
' ---- Adressen in die Userform eintragen
Dim rngC As Range, strAddress As String, varSB As Variant, lngX As Long
Dim lngZ As Long
Worksheets("Adressen").Select
varSB = Adressid 'Hier das Suchfeld definieren
With [A2:Z2000]
Set rngC = .Find(varSB, LookIn:=xlValues, Lookat:=xlPart)
If Not rngC Is Nothing Then
strAddress = rngC.Address
Do
On Error GoTo Ende
lngX = lngX + 1
lngZ = rngC.Row
With frmStamm
ta1.Value = Cells(lngZ, 1)
ta2.Value = Cells(lngZ, 2)
ta3.Value = Cells(lngZ, 3)
ta4.Value = Cells(lngZ, 4)
ta5.Value = Cells(lngZ, 5)
ta6.Value = Cells(lngZ, 6)
ta7.Value = Cells(lngZ, 7)
ta8.Value = Cells(lngZ, 8)
ta9.Value = Cells(lngZ, 9)
ta10.Value = Cells(lngZ, 10)
ta11.Value = Cells(lngZ, 11)
ta12.Value = Cells(lngZ, 12)
ta13.Value = Cells(lngZ, 13)
ta14.Value = Cells(lngZ, 14)
ta15.Value = Cells(lngZ, 15)
ta16.Value = Cells(lngZ, 16)
ta17.Value = Cells(lngZ, 17)
ta18.Value = Cells(lngZ, 18)
ta19.Value = Cells(lngZ, 19)
End With
Set rngC = .FindNext(rngC)
Loop While Not rngC Is Nothing And rngC.Address strAddress
End If
End With
Ende:
' ---- Forderungen in die Userform eintragen
Dim rngC2 As Range, strAddress2 As String, lngX2 As Integer
Dim lngZ2 As Integer
Worksheets("Forderungen").Select
varSB = Aktenzeichen 'Hier das Suchfeld definieren
With [A2:AZ2000]
Set rngC2 = .Find(varSB, LookIn:=xlValues, Lookat:=xlPart)
If Not rngC2 Is Nothing Then
strAddress2 = rngC2.Address
Do
On Error GoTo Ende1
lngX2 = lngX2 + 1
lngZ2 = rngC2.Row
Set rngC2 = .FindNext(rngC2)
Loop While Not rngC2 Is Nothing And rngC2.Address strAddress2
End If
End With
With frmStamm
tb1.Value = Cells(lngZ2, 1)
tb2.Value = Cells(lngZ2, 2)
tb3.Value = Cells(lngZ2, 3)
tb4.Value = Cells(lngZ2, 4)
tb5.Value = Cells(lngZ2, 5)
tb6.Value = Cells(lngZ2, 6)
tb7.Value = Cells(lngZ2, 7)
tb8.Value = Cells(lngZ2, 8)
tb9.Value = Cells(lngZ2, 9)
tb10.Value = Cells(lngZ2, 10)
tb11.Value = Cells(lngZ2, 11)
tb12.Value = Cells(lngZ2, 12)
tb13.Value = Cells(lngZ2, 13)
tb14.Value = Cells(lngZ2, 14)
tb15.Value = Cells(lngZ2, 15)
tb16.Value = Cells(lngZ2, 16)
tb17.Value = Cells(lngZ2, 17)
tb18.Value = Cells(lngZ2, 18)
tb19.Value = Cells(lngZ2, 19)
tb20.Value = Cells(lngZ2, 20)
tb21.Value = Cells(lngZ2, 21)
tb22.Value = Cells(lngZ2, 22)
tb23.Value = Cells(lngZ2, 23)
tb24.Value = Cells(lngZ2, 24)
tb25.Value = Cells(lngZ2, 25)
tb26.Value = Cells(lngZ2, 26)
tb27.Value = Cells(lngZ2, 27)
tb28.Value = Cells(lngZ2, 28)
tb29.Value = Cells(lngZ2, 29)
tb30.Value = Cells(lngZ2, 30)
tb31.Value = Cells(lngZ2, 31)
tb32.Value = Cells(lngZ2, 32)
tb33.Value = Cells(lngZ2, 33)
tb34.Value = Cells(lngZ2, 34)
tb35.Value = Cells(lngZ2, 35)
tb36.Value = Cells(lngZ2, 36)
tb37.Value = Cells(lngZ2, 37)
tb38.Value = Cells(lngZ2, 38)
End With
Ende1:
tb9.Value = Format(tb9.Value, "currency")
MsgBox Cells(lngZ2, 35)
Listenfelder.Range("Z2") = lngZ2
If lngZ2 = 0 Then
MsgBox "Fehler!" & "" & "Kann Zeile nicht finden!", vbCritical
End If
Forderungzeile = Listenfelder.Range("Z2").Value
Ich bitte um Rat!
Danke!