我想做什么:过滤一个数组,然后将过滤后的数据复制到另一个工作簿上 . 然后将刚粘贴的数据复制到同一工作簿中的另一个工作表上,但这次是在现有数据下面 .
我的想法:我在下面使用的代码用于帮助我从一个工作簿复制并粘贴到另一个工作簿并且工作得很好,
wb.Sheets("2014 Current Week").Range("C2:CC10000").Copy nwb.Sheets("2014 YTD").Range("C" & Rows.Count).End(xlUp).Offset(1, 0)
但是,如果我想在同一个工作簿中复制,它似乎不会以相同的方式工作 . 任何帮助,将不胜感激 . 谢谢!
Dim wb as workbook
Dim strs As String
Dim str As String
Dim nwb as workbook
Set wb = ThisWorkbook
strs = wb.Sheets("Macros").Range("H5") 'the 2014 address can be found in full in cell H5 in the Macros tab
set nwb = Workbooks.Open(strs) 'address of new workbook and opens it
With ActiveSheet
.AutofilterMode = False
'Filter this and that here'
End With
nwb.Sheets("ALL DATA").Range("A1:CA100000").Copy wb.Sheets("2014 Current Week").Range("C" & Rows.Count).End(xlUp)
'this one works, and copies exactly as I want into the 2014 Current Week tab
wb.Sheets("2014 Current Week").Range("C2:CC10000").Copy wb.Sheets("2014 YTD").Range("C" & Rows.Count).End(xlUp).Offset(1, 0)
'this one doesn't work, and does not copy or paste at all from that 2014 Current Week into the 2014 YTD tab of the same workbook
2 回答
您的代码看起来很好,不应该有任何问题 . 由于它似乎不起作用,您需要查看实际的
Worksheets
和涉及的数据 .您正在使用
End
查找最后一行数据 . 鉴于此,值得自己测试一下 . 转到C
列中Worksheet
的最后一行,然后按CTRL UP . 这将显示要粘贴数据的位置 .根据您的描述,最后一行是问题所在 . 由于存在一些影响
End
的杂散数据 .我刚刚测试了你的代码,它运行正常 . 它正确粘贴数据 . 检查工作表的名称 .