在数据验证VBA中使用添加类型和公式1:错误1004

时间:2017-12-04 11:14:15

标签: vba validation

我知道此问题已被覆盖过,我已尝试查看所有答案,但我仍然收到以下错误

1004 error: Application-defined or object-defined error.

以下是代码:

With ActiveSheet.Range("A10").Validation
    .Delete
    .Add Type:=xlValidateList, Formula1:=Join(DPHeight, ",")
    .IgnoreBlank = True
    .InCellDropdown = True
    .ShowInput = True
    .ShowError = True    
End With

DPHeight是先前生成的动态数组。 代码在

上停止

.Add

感谢任何帮助。谢谢

1 个答案:

答案 0 :(得分:0)

  • 打开一个新的Excel文件。
  • 写下这个:
Option Explicit
Sub TetMe()

    Dim DPHeight    As Variant
    DPHeight = Array("34", "46", "67")

    With ActiveSheet.Range("A10").Validation
        .Add Type:=xlValidateList, Formula1:=Join(DPHeight, ",")
        .IgnoreBlank = True
        .InCellDropdown = True
        .ShowInput = True
        .ShowError = True
    End With
End Sub

然后检查A10的值。应该是一个数据验证列表。