1

我正在尝试向一个单元格添加和删除数据验证(以及 inCellDropdown)Range。我第一次运行它工作正常。但我在后续执行时总是会出错。

我得到的错误是“HRESULT 异常:0x800A03EC”

这是代码:

If type = "a1" Then
  Try
    Me.Range("A1:A20").Validation.Delete()
    Me.Range("A1:A20").Validation.Add(Type:=Excel.XlDVType.xlValidateList, _
                    AlertStyle:=Excel.XlDVAlertStyle.xlValidAlertStop, _
                    [Operator]:=Excel.XlFormatConditionOperator.xlBetween, _
                    Formula1:="=rangedname1")
  Catch ex As Exception
    MsgBox(ex.ToString)
  End Try
ElseIf type = "b2" Then
  Try
    Me.Range("A1:A20").Validation.Delete()
    Me.Range("A1:A20").Validation.Add(Type:=Excel.XlDVType.xlValidateList, _
                    AlertStyle:=Excel.XlDVAlertStyle.xlValidAlertStop, _
                    [Operator]:=Excel.XlFormatConditionOperator.xlBetween, _
                    Formula1:="=rangedname2")
  Catch ex As Exception
    MsgBox(ex.ToString)
  End Try
EndIf

以前有没有人处理过这个问题?

4

0 回答 0