Ich möchte in einem Modul der Datei ("C:\Test\2.xls") auf eine Adressliste einer geschlossenen Datei zugreifen (Quelle/Datenbank = geschlossene Datei: "C:\1.xls"). Leider ist es mir bisher nicht gelungen, die Fehlermeldung Laufzeitfehler '9' zu vermeiden (Index ausserhalb des gültigen Bereichs).
Wie muss ich die untenstehenden Codes ändern, damit dies ohne Fehlermeldung gelingt?
Danke für Deine Hilfe!
Grüsse Gregor
Private Sub ComboBox1_Change()
Dim TB As Worksheet
Dim R%
Set TB = Workbooks("1.xls").Worksheets("Adressen")
R = ComboBox1.ListIndex + 2
TextBox1.Text = TB.Cells(R, 1)
TextBox2.Text = TB.Cells(R, 2)
TextBox3.Text = Trim(TB.Cells(R, 3) & " " & TB.Cells(R, 4))
TextBox4.Text = TB.Cells(R, 7)
TextBox5.Text = Trim(TB.Cells(R, 5) & " " & TB.Cells(R, 6))
TextBox6.Text = TB.Cells(R, 8)
TextBox7.Text = TB.Cells(R, 9)
TextBox8.Text = TB.Cells(R, 10)
End Sub
Private Sub CommandButton1_Click()
Dim TB As Worksheet
Dim lZeile%, i%
Set TB = Workbooks("1.xls").Worksheets("NeueListe")
If IsEmpty(TB.Cells(1, 1)) Then
lZeile = 1
Else
lZeile = TB.Cells(Rows.Count, 1).End(xlUp).Row + 1
End If
For i = 1 To 8
TB.Cells(lZeile, i) = frmSuchen.Controls("Textbox" & i).Value
Next i
End Sub
Private Sub UserForm_Initialize()
Dim lZeile$
lZeile = Workbooks("1.xls").Worksheets("Adressen"). _
Cells(Rows.Count, 1).End(xlUp).Address(False, False)
ComboBox1.RowSource = "Adressen!A2:" & lZeile
End Sub