我有兩個替補:VBA Excel中的ComboBox錯誤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
的問題是: 1)ActiveWorkbook.Worksheets("Menu").PositionsComboBox.List = ActiveWorkbook.Worksheets("Menu").Range(Cells(2, Range("_positions").Column), Cells(lastRowOfPositions, Range("_positions").Column)).Value
- 這是形式第一子和它工作得很好,沒有任何問題
2)ActiveWorkbook.Worksheets("Menu").EmployeesComboBox.List = ws.Range(ws.Cells(2, ws.Range(helperText).Column), ws.Cells(lastRowOfEmployees, ws.Range(helperText).Column)).Value
- 從第二子。
對我來說,他們是同一段代碼,只是這裏我使用範圍從不同的板材,與(1)其中,我使用範圍從同一張
第一個工作正常,第二次給了錯誤381 幫助請,因爲我找不到錯誤導致它
你檢查什麼'ws.Range(ws.Cells(2 ws.Range(helperText).COLUMN),WS。單元格(lastRowOfEmployees,ws.Range(helperText).Column)).value'作爲值返回? – UGP
我不能完全理解它,但我隱約記得我曾經有過類似的問題,這在代碼的位置有其原因。嘗試從標準代碼模塊運行代碼。 – Variatus