0
我正在尝试在受保护的文档中添加下拉列表。添加数据验证时的运行时错误1004
我使用的代码是:
Private Sub AddDropDown_Click()
ActiveSheet.Unprotect
Dim currCell As Range
Dim lastRow As Long
With ActiveSheet
lastRow = ActiveSheet.Cells(1048576, 1).End(xlUp).Row
End With
For Each currCell In Range("K4:K" & lastRow)
With currCell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=INDIREKT(J" & currCell.Row & ")"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Next currCell
ActiveSheet.Protect
End Sub
但是当我尝试运行它抛出Error 1004。新增的excecuted该行的代码。
大多数参数抛出当我尝试whatching他们在调试时相同的错误:
有没有人有一个想法是什么原因造成的?
首先,你需要用范围限定你的'formula',所以它需要是'cell.formula <>“”''。第二,什么是INDIREKt?你在使用Excel的德语设置吗? –
你的'公式'变量集在哪里? ('如果公式<>“”Then')你是不是指'Cell.Formula'?其次,您在代码中使用德语版的“间接”公式 - 试试英语。 –
@ShaiRado是的,我有德语的Excel版本,你也可以在屏幕截图中看到。在改变一些事情之前,公式是我在那里的一部分。从问题中删除它。 – lightlike