根据单元格的值进行不同的列表验证时出现 VBA 错误

根据单元格的值进行不同的列表验证时出现 VBA 错误

我正在尝试验证使用列表验证的特定列。如果(“表 (T)/ 行 (L)” 列 = “L”),则使用特定表;如果(“表 (T)/ 行 (L)” 列 = “t”),则使用另一个表。我使用下面的代码,但它不起作用 - 列表的值错误:

 Function check_alignment_column()

Dim cell As Range, j As String


msg = ""
Set rngCheck = Range([c3], Cells(Rows.Count, "C").End(xlUp))
Set rngcheck2 = Range([m3], Cells(Rows.Count, "M").End(xlUp))

For Each cell In rngCheck

If cell.value = "L" Then

With rngcheck2.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=Lists!E2:E5"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

End If

If cell.value = "T" Then
    With rngcheck2.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=Lists!F2:F29"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True

End With
End If

   Next cell

 End Function

相关内容