添加数据验证时的运行时错误1004。我该如何避免错误?

时间:2015-06-02 16:45:58

标签: excel vba excel-vba

我使用以下过程向单元格添加数据验证:

Sub SetDataValidationList(r As Range, s As String)
    Dim dv As Validation
    Set dv = r.Validation

    With dv
        .Delete
        If s <> "" Then
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=s
        Else
            'The backup string could be a parameter
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="None available"
        End If
    End With
End Sub

我在开发Excel文件几天时工作,但由于某种原因,行.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=s抛出运行时错误1004.可能是什么原因?我该如何避免错误?

s"1.1,PM,PA,OE,MOA1,MOA2,MOA3,MOA4"

1 个答案:

答案 0 :(得分:1)

我只是想通了。原因是纸张受到保护。