[英]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表标题名称AgeRange , B1 , C1 , D1 , E1 , F1等在同一行上
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.