Ich habe zwei U-Boote:VBA Excel ComboBox Fehler 381
1)
Sub InitializeComboBoxes()
Dim lastRowOfPositions As Integer, lastRowOfShifts As Integer
Application.ScreenUpdating = False
' POPULATE POSITIONS COMBOBOX
lastRowOfPositions = Module2.last_row("Menu", "_positions")
ActiveWorkbook.Worksheets("Menu").PositionsComboBox.List = ActiveWorkbook.Worksheets("Menu").Range(Cells(2, Range("_positions").Column), Cells(lastRowOfPositions, Range("_positions").Column)).Value
ActiveWorkbook.Worksheets("Menu").PositionsComboBox.ListIndex = 0
End Sub
2)
Sub InitializeEmployeeComboBox()
Dim lastRowOfEmployees As Integer
Dim sheetName As String
Dim ws As Worksheet
sheetName = ActiveWorkbook.Worksheets("Menu").ShiftsComboBoxRemove.Value
Set ws = ActiveWorkbook.Worksheets(sheetName)
Application.ScreenUpdating = False
Dim helperText As String
helperText = sheetName & "Name"
lastRowOfEmployees = Module2.last_row(sheetName, sheetName & "Name")
ActiveWorkbook.Worksheets("Menu").EmployeesComboBox.List = ws.Range(ws.Cells(2, ws.Range(helperText).Column), ws.Cells(lastRowOfEmployees, ws.Range(helperText).Column)).Value
ActiveWorkbook.Worksheets("Menu").EmployeesComboBox.ListIndex = 0
End Sub
Das Problem ist, mit: 1) ActiveWorkbook.Worksheets("Menu").PositionsComboBox.List = ActiveWorkbook.Worksheets("Menu").Range(Cells(2, Range("_positions").Column), Cells(lastRowOfPositions, Range("_positions").Column)).Value
- das ist Form erste sub und es funktioniert gut, keine Probleme
2) ActiveWorkbook.Worksheets("Menu").EmployeesComboBox.List = ws.Range(ws.Cells(2, ws.Range(helperText).Column), ws.Cells(lastRowOfEmployees, ws.Range(helperText).Column)).Value
- von zweiten sub.
Für mich sind sie gleiches Stück Code, nur hier verwende ich Bereich von verschiedenem Blatt, anders als in (1), wo ich Bereich verwenden, um von demselben Blatt
Zuerst eine funktioniert, gibt zweiten Fehler 381 Hilfe bitte, wie ich den Fehler nicht finden kann, der es verursacht
Haben Sie überprüft, was 'ws.Range (ws.Cells (2, ws.Range (helperText) .Column), ws. Zellen (lastRowOfEmployees, ws.Range (helperText) .Column)). Gibt Wert als Wert zurück? – UGP
Ich kann es nicht genau sagen, aber ich erinnere mich vage an ein ähnliches Problem, das ich einmal hatte, das seinen Grund hatte, wo der Code lag. Versuchen Sie, Ihren Code von einem Standardcodemodul auszuführen. – Variatus