vba 将在一张 Excel 中输入的某些数据复制/保存到另一张表并将其存储为数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27525604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copying/Saving certain data entered in one sheet of excel to another sheet and storing it as a database
提问by Devavratha Gm
I have sheet1 which looks like a form and data is entered in specific cells, On clicking a button the data entered must goto sheet2 in a row. Again when next set of datas are entered in sheet1 and button is pressed the datas should go to the next non empty row of sheet 2. Kindly help me out.
我的 sheet1 看起来像一个表单,并且数据是在特定单元格中输入的,单击按钮时,输入的数据必须连续转到 sheet2。再次当在 sheet1 中输入下一组数据并按下按钮时,数据应该转到 sheet 2 的下一个非空行。请帮帮我。
Sub Button5_Click()
Worksheets("Sheet1").Range("a2").Value = Worksheets("Sheet2").Range("h9")
Worksheets("Sheet1").Range("b2").Value = Worksheets("Sheet2").Range("h10")
Worksheets("Sheet1").Range("c2").Value = Worksheets("Sheet2").Range("h11")
Worksheets("Sheet1").Range("d2").Value = Worksheets("Sheet2").Range("h12")
End Sub
This code replaces specific cells again and again, What should i do in order for it to take the location by itself and append new dat
这段代码一次又一次地替换特定的单元格,我应该怎么做才能让它自己占据位置并附加新的数据
回答by Tim Williams
Sub Button5_Click()
dim s1,s2
Set s1 = Worksheets("Sheet1")
Set s2 = Worksheets("Sheet2")
with s1.cells(rows.count,1).end(xlup).offset(1,0).entirerow
.cells(,"a").Value = s2.Range("h9").Value
.cells(,"b").Value = s2.Range("h10").Value
.cells(,"c").Value = s2.Range("h11").Value
.cells(,"d").Value = s2.Range("h12").Value
End with
End Sub