2013-10-19 43 views
0

我有一個表單,我想填充兩個存儲在玫瑰和客戶工作表中的數據的列表框。下面的代碼行* *是給我的麻煩。活動工作簿和選擇問題,Excel VBA

Private Sub UserForm_activate() 

    Application.Workbooks("xx.xlsm").Activate 

    ActiveWorkbook.Worksheets("Customers").Range("B2").Select 
    Do Until IsEmpty(ActiveCell) = True 
    'loop through the customer table list 
     lstCustomers.AddItem ActiveCell.Value 
     ActiveCell.Offset(1, 0).Select 
    Loop 

    *****ActiveWorkbook.Worksheets("Roses").Range("A3").Select 
    Do Until IsEmpty(ActiveCell) = True 
    'loop through the roses table list 
     lstProducts.AddItem ActiveCell.Value 
     ActiveCell.Offset(1, 0).Select 
    Loop 

End Sub 

錯誤:範圍類的選擇方法失敗

我在做什麼錯?

+0

[有趣的閱讀](http://stackoverflow.com/questions/10714251/excel-macro-avoiding-using-select) –

回答

0

按順序選擇工作表和單元格,而不是單行。

請勿使用IsEmpty()來測試未填充的單元格。而是使用ActiveCell.Value =「」

相關問題