excel数据validation错误

我试图写一个数据validation列表,当它添加一个新的行如何不断得到运行时错误'1004'应用程序定义或对象定义的错误。

一直在这里寻找,尝试不同的代码,我可以得到我的手,但似乎都给了我同样的错误。

我确实设法让它以前工作,但不知道为什么现在不工作。

下面是除了数据validation部分之外的子代码。

Sub AddNewRecord() Dim vNewRow As Long ' Find the first empty row in the data table vNewRow = DataTable.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row ' Check for data in Field 1 If Trim(Range("formField1").Value) = "" Then Range("formField1").Activate MsgBox "Please enter data in Field 1!" Exit Sub End If ' Check for data in Field 2 If Trim(Range("formField2").Value) = "" Then Range("formField2").Activate MsgBox "Please enter data in Field 2!" Exit Sub End If ' Copy the data to the data table With DataTable .Cells(vNewRow, 1).Value = Range("formField1").Value .Cells(vNewRow, 2).Value = Range("formField2").Value End With ' Add data validation to data table With DataTable .Activate .Cells(vNewRow, 3).Select With Range("G" & vNewRow).Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:="In Progress,Completed" End With ' With Selection.Validation ' .Delete ' .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ ' xlBetween, Formula1:="In Progress,Completed" ' .IgnoreBlank = True ' .InCellDropdown = True ' .InputTitle = "" ' .ErrorTitle = "" ' .InputMessage = "" ' .ErrorMessage = "" ' .ShowInput = True ' .ShowError = True ' End With End With ' Clear data fields and reset the form With InputForm .Activate .Range("formField1").Value = "" .Range("formField2").Value = "" .Range("formField1").Select .Visible = False End With With DataTable .Activate .Cells(vNewRow, 1).Select End With End Sub 

谢谢。