vba 在状态更改后将一行从一个 wksheet 移动到同一工作簿中的另一个的宏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4866196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:36:28  来源:igfitidea点击:

A macro to move a row from one wksheet to another in the same workbook after status change

excelexcel-vbaworksheet-functionvba

提问by NikkiT

I have a workbook with 2 worksheets (1 sheet called final, 1 sheet called pending) that use the same column headings and column formulas.

我有一个工作簿,其中包含 2 个工作表(1 个工作表称为最终工作表,1 个工作表称为待处理),它们使用相同的列标题和列公式。

I am having a hard time figuring out a macro/VBA that will help me automatically transfer rows of data from the "pending" sheet to the "final" sheet once the status of the fourth column changes from pending to final. This is so that all the data for pending and final clients are kept on separate sheets.

我很难找出一个宏/VBA,它可以帮助我在第四列的状态从待定状态变为最终状态时自动将数据行从“待处理”工作表传输到“最终”工作表。这是为了将待定客户和最终客户的所有数据保存在单独的表格中。

Please help.

请帮忙。

回答by Paulo Bueno

Try something like this on your woorkbook code:

在你的工作簿代码上尝试这样的事情:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name = "pending" And Target.Column = 4 Then
    If Sh.Cells(Target.Row, Target.Column) = "final" Then
        Sh.Select
        Sh.Rows(LTrim(Str(Target.Row)) & ":" & LTrim(Str(Target.Row))).Select
        Selection.Copy ' or cut
        Sheets("final").Select
        Rows("20:20").Select ' here is your destination row... you must set a global to control it...
        Selection.Insert Shift:=xlDown
    End if
End Sub

Good luck!

祝你好运!