在vba中创建下拉列表验证时抛出异常

时间:2018-04-18 10:11:17

标签: vba excel-vba excel

Sub Example(x As Range, y As Range)

  With y.Validation
      .Delete
      .Add Type:=xlValidateList, Formula1:=x.Value
      .IgnoreBlank = True
      .InCellDropdown = True
      .InputTitle = ""
      .ErrorTitle = ""
      .InputMessage = ""
      .ErrorMessage = ""
      .ShowInput = True
      .ShowError = True
  End With
End Sub

这是我用来从逗号分区单元格创建下拉列表的功能。但是它的抛出异常   .Add Type:= xlValidateList,Formula1:= x.Value

错误是:

  

1004-应用程序定义的错误

以下是循环代码:

Private Sub Worksheet_Activate()
  Range("D2").Select

  Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("FacT&C")

  Dim LastRow As Long 'always use long instead of integer
  LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row

  Dim iRow As Long
   For iRow = 2 To LastRow
     Example ws.Cells(iRow, "AD"), ws.Cells(iRow, "R")
   Next iRow
End Sub

请帮帮我

0 个答案:

没有答案