Excel VBA Copy range into table

只谈情不闲聊 提交于 2019-12-22 17:56:30

问题


I have been unable to figure out how to paste a range (specifically one row) into a data table using VBA.

Right now there is a range of data in a worksheet named "RawData". On another sheet there is a graph that starts at (1, 1) and goes to (100, 33). The variable ThisValue contains the name of the sheet containing the table. The variable x contains the row number of the range I am attempting to transfer.

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.


回答1:


Tables should be addressed as ListObjects in VBA not as Ranges/Cells.

You should find what you require here in the section 'inserting rows and columns'.



来源:https://stackoverflow.com/questions/20437455/excel-vba-copy-range-into-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!