If 语句不会将结果复制到单独的页面
If Statement will not copy the results to a seperate page
正在创建一个 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
由于某种原因,它不会将数据复制到指定页面。它甚至根本不实际复制数据。有什么想法吗?
如上面的评论所述,您需要使用 sheet 引用,否则您将在 sheet 之间来回跳转,并且在第一次迭代后复制并粘贴到相同 sheet。您还必须指定要粘贴数据的位置并每次更改目的地,否则您将继续粘贴相同的数据。
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 month
正在创建一个 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
由于某种原因,它不会将数据复制到指定页面。它甚至根本不实际复制数据。有什么想法吗?
如上面的评论所述,您需要使用 sheet 引用,否则您将在 sheet 之间来回跳转,并且在第一次迭代后复制并粘贴到相同 sheet。您还必须指定要粘贴数据的位置并每次更改目的地,否则您将继续粘贴相同的数据。
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 month