在Excel VBA中,从数据validation下拉菜单中触发事件

我有一个表格,我想给用户一个计算types的select。 计算types通过数据validation中的列表select完成。 一旦select,我想它触发一个事件,然后将加载该types的select正确的单元格。 如何检测数据validation下拉列表中的数据更改事件,还是我需要使用活动的x控件?

工作表更改事件代码未激活:

Private Sub Worksheet_Change(ByVal Target As Range) If Target.Cells.count > 1 Then Exit Sub Application.EnableEvents = False On Error GoTo Errortrap '~~> Change it to the relevant string with which you want to compare StringToCheck = "+" If Not Intersect(Target, Range("D47")) Is Nothing Then '~~> Check for the cell value If Target.Value = StringToCheck Then 'setup row to capture addition fields Cells(33, 4).Value = "Input File 1" Cells(33, 4).Value = "Worksheet 1" Cells(33, 4).Value = "Cell 1" Cells(33, 4).Value = "Input File 2" Cells(33, 4).Value = "Worksheet 2" Cells(33, 4).Value = "Cell 2" End If End If LetsContinue: Application.EnableEvents = True Exit Sub Errortrap: MsgBox Err.Description Resume LetsContinue End Sub 

你的代码很好。 我在一个新的工作簿中试了一下,它做了它应该做的事情。
当您将D47中的值更改为“+”(无论是通过下拉还是手动),它将在单元格D33中依次写入六个值。

也许你打算写

  Cells(33, 4).Value = "Input File 1" Cells(33, 5).Value = "Worksheet 1" Cells(33, 6).Value = "Cell 1" Cells(33, 7).Value = "Input File 2" Cells(33, 8).Value = "Worksheet 2" Cells(33, 9).Value = "Cell 2" 

所以代码将填充范围D33:I33而不是将所有内容写入D33