【问题标题】:Excel VBA - Worksheet_Change drop-down listExcel VBA - Worksheet_Change 下拉列表
【发布时间】:2016-02-04 16:51:46
【问题描述】:

您好 Stackoverflow 社区,

如果满足条件,我想添加数据验证下拉列表。

使用 Excel VBA,我想添加下拉列表以填充到作为我的帐户状态的 N 列中,每当“Final Recon”一词出现在作为我的评估状态的 C 列中时,但仅在“ Final Recon”出现在 C 列中。

使用 Excel VBA - Private Sub Worksheet_Change(ByVal Target as Range):

如果“Final Recon”出现在 C 列中,则使用以下状态填充下拉列表:“Final”或“Under Review”,否则不要填充下拉列表。

我可以使用非 VBA 验证列表,但在这种类型的评估审核中我需要使用 VBA 版本。

这就是我到目前为止所拥有的,我几乎被卡住了。 我在 C 列中有“Final Recon”,如果最终侦察出现在 C 列中,则使用“Final”和“Under Review”选项填充下拉列表。

但由于某种原因,当 Final Recon 出现在 C 列时,drop-dwon 列表没有填充到 N 列中。

提前感谢您提供的任何帮助或解决方案。

 Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Column = 1 Then

    ThisRow = Target.Row

    If Target.Value = "Final Recon" Then

    With Selection.Validation
        .Range ("N" & ThisRow)


.Delete
.Add Type:=xlValidateList, Formula1:="=Final", Formula2:="=Under Review"
 End With

    Else
        Range("N" & ThisRow) = ""
    End If
  End If
 End Sub

【问题讨论】:

  • ......... 如果 Target.Column = 3 Then
  • 没有醒来。我需要重新访问代码。

标签: vba excel


【解决方案1】:

我能够弄清楚。我遇到的唯一问题是 如果“Final Recon”不在“C”列中,则不显示下拉菜单。

   On Error Resume Next

 If Target.Column = 3 Then

   If Target.Validation.Type = "Final Recon" Then

    Application.EnableEvents = False

     ''get the data drop-down validation list

    Target.Offset(0, 11).Select

    With Selection.Validation


  .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop
     Operator:=xlBetween, _                      
  Formula1:="Final", Formula2:="Under Review"

  .IgnoreBlank = True
  .InCellDropdown = True
  .InputTitle = ""
  .ErrorTitle = ""
  .InputMessage = ""
  .ErrorMessage = ""
  .ShowInput = True
  .ShowError = True

  End With

 Else
  Target.Offset(0, 11).Value = ""

   End If
 End If

 exitHandler:
   Application.EnableEvents = True
   Exit Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 2013-11-04
    • 1970-01-01
    相关资源
    最近更新 更多