2012-10-25 41 views
0

我想創建一個從特定單元格開始的列中的每個單元格的下拉列表。以下是我已經產生:無法弄清楚爲什麼下面的VBA宏失敗

Public Sub Dropdown() 
    Dim dvList As String 

    dvList = "Option1, Option2, Option3" 

    With ActiveSheet.Range("C25").Resize(50, 1).Validation 
     .Delete 
     .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ 
     xlBetween, Formula:=dvList 
     .IgnoreBlank = True 
     .InCellDropdown = True 
     .InputTitle = "" 
     .ErrorTitle = "" 
     .InputMessage = "" 
     .ErrorMessage = "" 
     .ShowInput = True 
     .ShowError = True 
    End With 
End Sub 

我有這行的一個問題:

.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ 
      xlBetween, Formula:=dvList 

當我運行這段代碼,我不斷收到:

Run-time error '1004': 

Application-defined or object-defined error 

我不不知道爲什麼會發生這種情況,這似乎是這樣做的。有人能指出我的錯誤嗎?

回答

3

嘗試將其更改爲Formula1:=dvList

+1

+1。這裏是[MSDN參考。](http://msdn.microsoft.com/en-us/library/office/ff837441.aspx)您還會注意到缺少Validation.Formula屬性。 –

相關問題