vba Excel - 如果单元格包含特定文本,则将整行移动到下一个工作表中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19178888/
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
Excel - move a whole row into the next worksheet if cell contains specific text
提问by user2846096
I am trying to set up a formula where worksheet 1 is a list of install jobs for the month, there are several columns showing customers details and at the last column showing the progress of the job from a drop down list.
我正在尝试设置一个公式,其中工作表 1 是该月的安装作业列表,有几列显示客户详细信息,最后一列显示下拉列表中的作业进度。
If the job is "completed" then I would like the entire row to be copied into the next worksheet (worksheet 2) and if the job is in progress then it does not go onto the next worksheet.
如果作业已“完成”,那么我希望将整行复制到下一个工作表(工作表 2)中,如果作业正在进行中,则它不会进入下一个工作表。
i also have several failed reasons would it be possible to have a this data transferred to (worksheet 3) to show a list of filed jobs from sheet 1
我也有几个失败的原因是否可以将此数据传输到(工作表 3)以显示工作表 1 中提交的工作列表
Any guidance would be gratefully received.
任何指导将不胜感激。
回答by user2843099
Sub copyJobs()
Dim r1
Dim r2
Dim r3
r1 = 1
r2 = 1
r3 = 1
While Sheets("Sheet1").Range("A" & LTrim(Str(r1))) <> ""
If Sheets("Sheet1").Range("B" & LTrim(Str(r1))) = "completed" Then
Sheets("Sheet1").Range(LTrim(Str(r1)) & ":" & LTrim(Str(r1))).Copy
Sheets("Sheet2").Range("A" & LTrim(Str(r2))).PasteSpecial xlPasteAll
r2 = r2 + 1
End If
If Sheets("Sheet1").Range("B" & LTrim(Str(r1))) = "failed" Then
Sheets("Sheet1").Range(LTrim(Str(r1)) & ":" & LTrim(Str(r1))).Copy
Sheets("Sheet3").Range("A" & LTrim(Str(r3))).PasteSpecial xlPasteAll
r3 = r3 + 1
End If
r1 = r1 + 1
Wend
End Sub
It will start with row 1 on sheet1 until the value in column A is empty. In my example the status was in column B, you can change this of course.
它将从 sheet1 上的第 1 行开始,直到 A 列中的值为空。在我的示例中,状态在 B 列中,您当然可以更改它。