【发布时间】:2015-11-13 09:36:30
【问题描述】:
我在下面发送了一些代码,但无法让它工作。
Sub mybus()
Dim x As Long
x = 2
'start the loop
Do While Cells(x, 1) <> ""
'look for data with "bus"
If Cells(x, 1).Value = "bus" Then
'copy the entire row if it contains bus
Workbooks("book1").Worksheets("Sheet1").Rows(x).Copy
'Go to sheet 2 activate it, we want the data here
Workbooks("book1").Worksheets("Sheet2").Activate
'Find the first empty row in sheet2
erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'paste the data here
ActiveSheet.Paste Destination:=Worksheets("sheet2").Rows(erow)
End If
'go to sheet1 again and activate it
Worksheets("Sheet1").Activate
x = x + 1
Loop
End Sub
【问题讨论】:
-
不要复制/粘贴,但要回答,你需要
Destination:=Worksheets("sheet2").Rows(erow+1) -
@findwindow -
erow已经用Range.Offset property 排序到一个新的空白行。 -
你知道@Jeeped,并不是每个人都是像你这样的代码战士,他们可以阅读未格式化的代码,就像你可以 =P 顺便说一句,切线,但想帮我一个忙并为我解决 this请问?