多个数据验证表更改

时间:2019-05-05 10:53:49

标签: excel vba

我正在尝试根据2个数据验证下拉菜单中的选择创建2个工作表更改。我已经按照需要进行了第一个更改,但是我正在努力进行第二个更改-它不复制/粘贴单元格,也没有调试错误。

任何帮助将不胜感激!

编辑:我的原始代码来自其他版本,这是正确的代码:

''First Change copies another range of cells from one sheet to another       

Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("D17")) Is Nothing Then Exit Sub
        Select Case Target.Value
            Case ""
                With Sheets("PrintSheet")
                .Rows(16 & ":" & .Rows.Count).Delete
                End With
            Case "New"
                Sheets("DevicePrep").Range("A1:D23").Copy Sheets("PrintSheet").Range("B16")
            Case "Re-Issued"
                Sheets("DevicePrep").Range("F1:I23").Copy Sheets("PrintSheet").Range("B16")
        End Select

    ''Second Change copies another range of cells from one sheet to another         

    If Intersect(Target, Range("D19")) Is Nothing Then Exit Sub
        Select Case Target.Value
            Case ""
                With Sheets("PrintSheet")
                .Rows(40 & ":" & .Rows.Count).Delete
                End With
            Case "Account Management"
                Sheets("AccountManagement").Range("A1:D23").Copy Sheets("PrintSheet").Range("B40")
        End Select
End Sub

1 个答案:

答案 0 :(得分:0)

更改事件中的关键字是TargetIf Target.Address = "$D$17"将导致在更改D17时执行Change事件。然后,您可以检查Target单元格的值。无需指定需要更改的单元,它将在每次更改后运行。

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address="$D$17" then
      Select Case Range("D17")