Excel VBA Copy/Paste 范围到另一个工作表中的下一个可用单元格
Excel VBA Copy/Paste Range to the next available cell in another worksheet
我想做的事:对数组进行过滤,然后将过滤后的数据复制到不同的工作簿中。然后复制刚刚粘贴到同一工作簿中的另一个工作表上的数据,但这次在现有数据下方。
我的想法:我在下面使用的代码用于帮助我从一个工作簿复制和粘贴到另一个工作簿并且运行良好,
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
我刚刚测试了你的代码,它工作正常。它正确粘贴数据。检查您的工作表名称。
您的代码看起来不错,应该没有任何问题。由于它似乎不起作用,您需要查看实际 Worksheets
和涉及的数据。
您正在使用 End
查找最后一行数据。鉴于此,值得您自己进行测试。转到 C
列中 Worksheet
的最后一行,然后按 CTRL + UP。这将向您显示要将数据粘贴到何处。
根据您的描述,最后一行是问题所在。由于有一些杂散数据影响了 End
。
我想做的事:对数组进行过滤,然后将过滤后的数据复制到不同的工作簿中。然后复制刚刚粘贴到同一工作簿中的另一个工作表上的数据,但这次在现有数据下方。
我的想法:我在下面使用的代码用于帮助我从一个工作簿复制和粘贴到另一个工作簿并且运行良好,
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
我刚刚测试了你的代码,它工作正常。它正确粘贴数据。检查您的工作表名称。
您的代码看起来不错,应该没有任何问题。由于它似乎不起作用,您需要查看实际 Worksheets
和涉及的数据。
您正在使用 End
查找最后一行数据。鉴于此,值得您自己进行测试。转到 C
列中 Worksheet
的最后一行,然后按 CTRL + UP。这将向您显示要将数据粘贴到何处。
根据您的描述,最后一行是问题所在。由于有一些杂散数据影响了 End
。