【问题标题】:VBA: Check dropdown list for updates and copy rows, if neededVBA:如果需要,检查下拉列表以获取更新和复制行
【发布时间】:2017-06-09 13:22:32
【问题描述】:

我想创建一个宏,用于检查“I:I”列是否有下拉列表中的任何更改。此下拉列表包含几个条目。输入“已拒绝”条目后,应将整行复制到另一个工作表(“已拒绝”)并删除主工作表中的行(“数据”)。这也意味着,该行将始终复制到工作表中先前条目的下方(“已拒绝”)。

我从来没有使用过 Worksheet_Change 也没有使用过 Intersect 函数,所以每一个帮助都非常感谢。

提前感谢您的支持。

【问题讨论】:

  • 您需要Worksheet_Change 而不是Worksheet_SelectionChangeThis 将帮助您开始
  • 您在哪里输入“拒绝”,行在哪里?我:我也在同一个“数据”工作表中吗?给我们看一些数据

标签: vba excel worksheet-function


【解决方案1】:

我刚刚找到了一个解决方案,感谢您的想法:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim shtDeal As String
Dim shtDecl As String
Dim lastrow As Integer

shtDeal = "Name 1"
shtDecl = "Name 2"


If Not Intersect(Target, Range("F1:F10000")) Is Nothing Then

    On Error GoTo ErrHelp

    If Target = "Declined by x" Or _
    Target = "Declined by y" Or _
    Target = "Declined by z" Then

        lastrow = Worksheets(shtDecl).Range("A" & Rows.Count).End(xlUp).Row + 1
        Target.EntireRow.Copy Destination:=Worksheets(shtDecl).Range("A" & lastrow)
        MsgBox "Auf Grund Ihrer Auswahl wurde diese Datenreihe auf das Arbeitsblatt 'Declined' verschoben."
        Target.EntireRow.Delete

    End If

End If

Done:
Exit Sub

ErrHelp:
End Sub

也许这可以帮助其他有同样问题的人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多