简体   繁体   English

Excel VBA 将范围复制到表格中

[英]Excel VBA Copy range into table

I have been unable to figure out how to paste a range (specifically one row) into a data table using VBA.我一直无法弄清楚如何使用 VBA 将范围(特别是一行)粘贴到数据表中。

Right now there is a range of data in a worksheet named "RawData".现在,名为“RawData”的工作表中有一系列数据。 On another sheet there is a graph that starts at (1, 1) and goes to (100, 33).在另一张纸上有一个从 (1, 1) 开始到 (100, 33) 的图。 The variable ThisValue contains the name of the sheet containing the table.变量 ThisValue 包含包含表格的工作表的名称。 The variable x contains the row number of the range I am attempting to transfer.变量 x 包含我尝试传输的范围的行号。

I am currently using this code:我目前正在使用此代码:

Sheets("RawData").Select
Cells(x, 1).Resize(1, 33).Copy
Sheets(ThisValue).Select
NextRow = Cells(Rows.Count, 1).End(xlUp).row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste

The problem that I am facing is that it pastes the range of data directly below the table and not in the table.我面临的问题是它将数据范围直接粘贴在表格下方而不是表格中。 Any help would be greatly appreciated.任何帮助将不胜感激。

Tables should be addressed as ListObjects in VBA not as Ranges/Cells.表格应该在 VBA 中作为 ListObjects 而不是 Ranges/Cells 来寻址。

You should find what you require here in the section 'inserting rows and columns'.你会发现你需要在这里一节“插入行和列”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM