ich probiere mich gerade an vba und habe folgendes Problem:
Ich habe in einer Datei die Tabellen 1-6. Keine Tabelle hat einen vba-Code.
Ich habe ein Modul in der Datei, in dem u.a. folgendes Makro steht:
Sub TNneuAufruf()
'Aufruf des Userforms frmTNneu
frmTNneu.Show
End Sub
Die Userform frmTNneu besteht zurzeit aus diversen Textfeldern und zwei voneinander abhängigen Kombinationsfeldern. Die Abhängigkeit steht u.a. in der Userform_initialize().
Das Problem:
Ich will von Excel das Userform mit dem Makro "TNneuAufruf()" aufrufen, wobei es ja initialisiert wird. Wenn ich nun in Tabelle 1-4 stehe und das Makro aufrufe, funktioniert alles wunderbar (die erste Combobox hat Items, die zweite wird entsprechend gefüllt). Stehe ich jedoch in Tabelle 5 oder 6 und rufe das Makro auf enthält keine Combobox Werte.... Hat jemand eine Idee, woran das liegen kann?
Egal aus welcher Tabelle ich das Makro ausführe, wird übrigens wohl das initialize ausgeführt. Getestet durch Caption = "Testcaption" s.u.
Hier der Code in der frmTNneu:
Option Explicit
Dim aRow As Long
Dim col As Collection
Dim iRow, x As Long
Private Sub UserForm_Initialize()
aRow = IIf(IsEmpty(Sheets("Listen").Range("c65536")), Range("c65536").End(xlUp).Row, 65536)
Caption = "Testcaption"
Set col = New Collection
On Error Resume Next
For iRow = 2 To aRow
col.Add Sheets("Listen").Cells(iRow, 3), Sheets("Listen").Cells(iRow, 3)
If Err = 0 Then
cbBereich.AddItem Sheets("Listen").Cells(iRow, 3)
Else
Err.Clear
End If
Next iRow
On Error GoTo 0
cbBereich.SetFocus
End Sub
Private Sub cbBereich_Change()
Dim col As Collection
Dim iRow, x As Long
cbKurs.Clear
Set col = New Collection
On Error Resume Next
For iRow = 2 To aRow
col.Add Sheets("Listen").Cells(iRow, 4), Sheets("Listen").Cells(iRow, 4)
If Err = 0 And Sheets("Listen").Cells(iRow, 3) = cbBereich.Value Then
cbKurs.AddItem Sheets("Listen").Cells(iRow, 4)
Else
Err.Clear
End If
Next iRow
On Error GoTo 0
For x = col.Count To 1 Step -1
col.Remove (x)
Next x
cbKurs.SetFocus
End Sub
Private Sub cmdAbbruch_Click()
Unload frmTNneu
End Sub
Private Sub cmdSpeichern_Click()
TNneu_speichern
End Sub