[英]Copy rows into a Workbook sheet based on cell value
Am very new and have been trying my best to self help myself but after a hour or so I have give up and now need help, I am trying to use the below code I have found on here to copy the "OK" lines in Workbook 1 sheet 1 column I into a new sheet in workbook 2 sheet 1. 我是一个非常新的人,一直在尽我所能来自助,但是大约一个小时后,我放弃了,现在需要帮助,我正在尝试使用下面的代码在我的工作簿中复制“ OK”行从工作表2工作表1中的新工作表中将1页1列I
I don't need to copy the "ERROR" part but have left this in until I got the code working. 我不需要复制“错误”部分,但是在我让代码正常工作之前一直保留此部分。
I would also like to keep all the data copied in to workbook 2 as at the moment the previous date is being replaced with the new data. 我还想将所有数据复制到工作簿2中,因为之前的日期已被新数据替换。
FilterAndCopy()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Dim lngLastRow As Long
Dim OKSheet As Worksheet, ErrorSheet As Worksheet
Set OKSheet = Sheets("Sheet1") ' Set This to the Sheet name you want all Ok's going to
Set ErrorSheet = Sheets("Sheet2") ' Set this to the Sheet name you want all Error's going to
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
With Range("A1", "I" & lngLastRow)
.AutoFilter
.AutoFilter Field:=9, Criteria1:="OK"
.Copy OKSheet.Range("A1")
.AutoFilter Field:=9, Criteria1:="ERROR"
.Copy ErrorSheet.Range("A1")
.AutoFilter
End With
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub
Thanks 谢谢
Well your code is not working because you need to write 好吧,您的代码无法正常工作,因为您需要编写
sub FilterAndCopy()
At the beggining of your sub, try it and see if it works. 在您的潜艇开始时,尝试一下,看看它是否有效。
What you can do to check if there is data in the colum is: 您可以检查列中是否有数据:
Dim r as range
set r = Range("a1")
while r.value <> ""
r= r.offset(0,1)
end while
and use "r" as your paste range instead of A1 并使用“ r”代替A1作为粘贴范围
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.