打开电子表格时出现VBA错误“编译错误”

时间:2014-09-10 16:49:35

标签: vba compilation

我有一个电子表格,它使用了单元格D11中的值(D11中的值来自ComboBox1)和表格#34; inputform"在同一工作表上创建ComboBox74的列表,其中D11中的值与工作表" PS_Group_Level"的A列中的值匹配。在PS_Group_Level工作表中,A列中将出现重复值,D列中将出现唯一值。然后,它将使用D列中的唯一值填充组合框列表,其中A列中存在相应的匹配。

希望我已经清楚地解释了我的情景。这是我使用的代码,它工作得很好,但是在打开工作簿时收到错误。 - "编译错误:未找到方法或数据成员"。我已经检查过组合框和工作表名称的名称是否正确,甚至使用了具有不同名称的新框,我得到了相同的结果。 VBA编辑器突出显示清除ComboBox74的代码

请帮忙! 谢谢!

Private Sub ComboBox1_Change()

'finds value for PS Type and PS Area
box1val = ThisWorkbook.Sheets("inputform").Range("d11")

'loop through col A to find last row
lr = ThisWorkbook.Sheets("PS_Group_Level").Cells(Rows.Count, 1).End(xlUp).Row

'clear combobox for PS Type and PS Area Override
Me.ComboBox74.Clear

' loop through
For x = 2 To lr
    If box1val = ThisWorkbook.Sheets("PS_Group_Level").Cells(x, 1) Then
        With ComboBox74
        'add to combobox for PS Type and PS Area Override
        .AddItem ThisWorkbook.Sheets("PS_Group_Level").Cells(x, 4)
        End With
    End If
Next x
End Sub

0 个答案:

没有答案