我使用以下过程向单元格添加数据验证:
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"
答案 0 :(得分:1)
我只是想通了。原因是纸张受到保护。