Excel VBA将范围复制到表中 [英] Excel VBA Copy range into table

查看:104
本文介绍了Excel VBA将范围复制到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直无法弄清楚如何使用VBA将范围(特别是一行)粘贴到数据表中.

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

现在,在名为"RawData"的工作表中有一系列数据.在另一张纸上,有一个图从(1,1)开始到(100,33).变量ThisValue包含包含表的工作表的名称.变量x包含我要传输的范围的行号.

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.

推荐答案

表应在VBA中作为ListObjects而不是Ranges/Cells.

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'.

这篇关于Excel VBA将范围复制到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆