简体   繁体   English

将单元格数据复制到新的表格行

[英]Copy cell data to a new table row

I'm very new to Excel VB scripting and i'm looking for information on how to copy specific cell data to a new sheet with a table and add a new line for each time you press the button to copy. 我对Excel VB脚本非常陌生,我正在寻找有关如何将特定单元格数据复制到带有表的新工作表中的信息,并在每次按按钮进行复制时添加新行。 Let me try to explain better I have 1 sheet named Values and one named Data 让我尝试更好地解释我有一个名为“ 值”的工作表和一个名为“ 数据”的工作表

Excel Version 2013 Excel 2013版

Value Sheet Information in Cells A2, H17, H19, H21, H23, H25, H27, H29, H31, H33, H35 and H37 单元格A2,H17,H19,H21,H23,H25,H27,H29,H31,H33,H35和H37的值表信息

Data Sheet 数据表

Tablename: SurveyData Table Header names AgeRange , B1 , C1 , D1 , E1 , F1 , and so on all on the same row 表名:SurveyData表标题名称AgeRangeB1C1D1E1F1等在同一行上

H17 = B1 H17 = B1

H19 = C1 H19 = C1

And so on 等等

When you click on the button it should copy all these values from these cells to a new table row in the Data Sheet 当您单击按钮时,应将所有这些值从这些单元格复制到数据表中的新表行中

I don't know how possible this is to do within Excel but i'm hoping there will be some options on how to perform this within Excel. 我不知道在Excel中这样做的可能性,但我希望在Excel中会有一些选择。

Thank you for taking your time and hope this explanation of mine makes sense. 感谢您抽出宝贵的时间,并希望我的这种解释有意义。

Edit: I did a huge error when expressing my request, The data in the entry sheet is spread out across multiple rows and cells. 编辑:表达请求时我犯了一个严重错误,条目表中的数据分布在多个行和单元格中。 I want to take these individual cells to be pasted into a new sheet on a new row. 我想将这些单个单元格粘贴到新行的新表中。 so it will look something like this 所以看起来像这样

When you click the button it copies all data from Sheet 1 to Sheet 2 each click creates a new row with data filled in on each cell that was copied from sheet 1 under their corresponding cell. 当您单击按钮时,每次单击都会将所有数据从工作表1复制到工作表2,这将创建一个新行,其中填充有从工作表1的相应单元下的工作表1复制的每个单元格上的数据。

AgeRange  B  C  D  E  F  G
15-20     1  1  0  1  0  1
20-25     1  0  1  1  1  0

And so on. 等等。 I got the copy down but getting each individual cell to be pasted into one row in a new column and when done go to a new line for new data is the issue. 我记下了副本,但是将每个单元格粘贴到新列的一行中,完成后转到新行以获取新数据是问题。

I do not know if i make any sense here 我不知道我在这里是否有意义

Regards 问候

Johan 约翰

Sub CopySheet1PasteSheet2 () 子CopySheet1PasteSheet2()

count=Worksheets("Sheet1").Cells(Worksheets("Sheet2").Rows.Count, "A").End(xlUp).Row count = Worksheets(“ Sheet1”)。Cells(Worksheets(“ Sheet2”)。Rows.Count,“ A”)。End(xlUp).Row

Worksheets("Sheet2").Cells(count+1,1) =Worksheets("Sheet1").Cells(1,2) 'for A2 Worksheets(“ Sheet2”)。Cells(count + 1,1)= Worksheets(“ Sheet1”)。Cells(1,2)'对于A2

Worksheets("Sheet2").Cells(count+1,2) = Worksheets("Sheet1").Cells(2,5) 'for B5 Worksheets(“ Sheet2”)。Cells(count + 1,2)= Worksheets(“ Sheet1”)。Cells(2,5)'对于B5

End Sub 结束子

In order to add next row you need to count rows in Data Sheet: 为了添加下一行,您需要对数据表中的行进行计数:

Dim count as integer; 昏暗计数为整数; count=Worksheets("Data").Cells(Worksheets("Data").Rows.Count, "A").End(xlUp).Row count = Worksheets(“ Data”)。Cells(Worksheets(“ Data”)。Rows.Count,“ A”)。End(xlUp).Row

To copy values from worksheets from A2 to V1 Worksheets("Data").Cells(count+1,1) = Worksheets("Values").Cells(1,2) 将工作表中的值从A2复制到V1工作表(“ Data”)。Cells(count + 1,1)= Worksheets(“ Values”)。Cells(1,2)

And then next cells accordingly 然后相应的下一个单元格

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

相关问题 如何从单元格中复制并粘贴到不同表格 VBA 的新行中 - How to copy from a cell and paste in a new row of a different table VBA 插入新行并将一个单元格复制到其他单元格 - Insert new row and copy a cell to other cell 如果表格范围内的单元格值等于“新建”,则复制整行并粘贴为工作表 1 中下一个空单元格中的值 - If cell value in table range equals “New” copy entire row and paste as values in sheet 1 in the next empty cell 将单元格数据复制为字符串并粘贴到新单元格中 - Copy cell data as string and paste into new cell 如何复制包含文档超链接的单元格并将其放入新行的表格列中 - How can I copy a cell containing a document Hyperlink and put it into a table column on a new row 复制单元格和相邻单元格并插入为新行:Excel VBA - Copy cell and adjacent cell and insert as new row: Excel VBA 插入新行并使用Excel中的命令/代码将数据从单元格复制到该行 - Insterting a new Row and Copy the data from a cell to it using Commands/code in excel Excel VBA根据单元格数据将整个行复制到新工作表 - Excel VBA copy entire row to new sheet based off cell data 添加新行并将数据复制到该行 - Add New Row and Copy Data To That Row 如何将数据复制到连续的每个其他单元格中? - How to copy data into every other cell in a row?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM