创建一条If语句,根据某列中的月份对我的数据进行排序。代码是这样的
Worksheets("Project Info").Activate
Dim month As Long
Application.ScreenUpdating = False
For month = Cells(Rows.Count, 23).End(xlUp).Row To 1 Step -1
If InStr(1, Cells(month, 23).Value Like "1/*", 1) _
Then Cells(month, 23).EntireRow.Copy
Worksheets("January").Activate
ActiveSheet.Paste
Next month由于某些原因,它不会将数据复制到指定的页面中。它甚至根本不会实际复制数据。有什么想法吗?
发布于 2019-03-13 21:17:08
正如在上面的注释中提到的,您需要使用工作表引用,否则您将在工作表之间来回跳转,并且在第一次迭代之后,您将复制并粘贴到同一工作表。您还必须指定粘贴数据的位置,并每次更改目标位置,否则将继续粘贴相同的数据。
Dim ws1 as Worksheet
Dim ws2 as Worksheet
Set ws1 = Worksheets("Project Info")
Set ws2 = Worksheets("January")
Dim month As Long
Dim t as Long
Application.ScreenUpdating = False
t=1
For month = ws1.Cells(Rows.Count, 23).End(xlUp).Row To 1 Step -1
If InStr(1, ws1.Cells(month, 23).Value Like "1/*", 1) Then
ws1.Cells(month, 23).EntireRow.Copy
ws2.Rows(t).PasteSpecial xlPasteAll
t=t+1
End if
Next monthhttps://stackoverflow.com/questions/55141261
复制相似问题