我的代码需要帮助。逻辑是:如果他们都说"完成"然后将第一行代码复制到第2页。如果有人说除了"完成"将它复制到工作表3.它可能有不止一行,旁边有"完成"。我有一个web_scraper用数据闪烁这个区域,我需要对它进行排序。包含的IMAGE基本上是数据的样子。完整后还有(3)个空格,所以我把它包含在我的代码中。
Sub test()
Dim P, lastrow4
lastrow4 = Sheets("Sheet1").Range("a" & Rows.Count).End(xlUp).Row
For P = 1 To lastrow4
'****if complete****
'if row one is complete and row 2 is blank place in sheet 2
If Sheets("sheet1").Cells(P, "A").Value = "COMPLETE " And Sheets("sheet1").Cells(P + 1, "A").Value = "" Then
Sheets("Sheet1").Cells(P, "A").EntireRow.Copy Destination:=Sheets("sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
****/if not complete*********************
'if row 1 isn't complete and is not blank put in sheet 5
If Sheets("sheet1").Cells(P, "J").Value <> "COMPLETE " And Sheets("sheet1").Cells(P, "J").Value <> "" Then
Sheets("Sheet1").Cells(P, "J").EntireRow.Copy Destination:=Sheets("sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next P
End Sub
答案 0 :(得分:0)
下面有一些建议,但是你的一些代码还不清楚,比如偏移需要2个值.offset(1,0)。您还使用Rows.count-您也应用了哪些行?所有在工作表中?你需要使用Range(&#34; A1:A2&#34;)。例如Rows.Count。
我已经更正了您的尺寸标注,并更改了一个混乱的范围/单元格引用,但您需要将其更容易理解,然后才能正确更正。
请参阅此处以获取有关单元格引用的良好起点
<强> http://www.excel-easy.com/vba/examples/formulaR1C1.html 强>
Sub test()
Dim P as long, lastrow4 as long
lastrow4 = Sheets("Sheet1").Range("a" & Rows.Count).End(xlUp).Row
For P = 1 To lastrow4
'****if complete****
'if row one is complete and row 2 is blank place in sheet 2
If Sheets("sheet1").Cells(P, 1).Value = "COMPLETE " And Sheets("sheet1").Cells(P + 1, 1).Value = "" Then
Sheets("Sheet1").Cells(P, 1).EntireRow.Copy Destination:=Sheets("sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
'****/if not complete*********************
'if row 1 isn't complete and is not blank put in sheet 5
If Sheets("sheet1").Cells(P, "J").Value <> "COMPLETE " And Sheets("sheet1").Cells(P, "J").Value <> "" Then
Sheets("Sheet1").Cells(P, "J").EntireRow.Copy Destination:=Sheets("sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next P
End Sub
答案 1 :(得分:0)
我实际上并没有处理过表1和表1 2我刚刚改变了它的帮助。这适用于从表2向下的第15行,如果真正的表5为假,则移至第4页
Dim P, lastrow4
P = 15
lastrow4 = Sheets("Sheet2").Range("J" & Rows.Count).End(xlUp).Row
Dim check As Boolean
Sheets("Sheet2").Cells(lastrow4, "J").EntireRow.Copy Destination:=Sheets("sheet4").Range("A" & Rows.Count).End(xlUp).Offset(1)
For P = 15 To lastrow4
check = Sheets("sheet2").Range("J" & P) = "COMPLETE "
If check = False Then
Sheets("Sheet2").Cells(P, "J").EntireRow.Copy Destination:=Sheets("sheet5").Range("A" & Rows.Count).End(xlUp).Offset(1)
Sheets("sheet4").Range("A" & Rows.Count).End(xlUp).EntireRow.Delete
End If
Next P