vba 将文本框中的内容复制并粘贴到工作表单元格区域?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9461260/
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
Copy and paste content from a textbox to a worksheet cell range?
提问by Chinraj Palanichamy
I'm working on a VBA project to automate the Excel tool for a service desk queries tracker. I want, once the command button is clicked, to copy the content from a textbox to another worksheet row. If I repeat the task, the textbox content should be saved in the next empty cell of the same row.
我正在处理一个 VBA 项目,以自动化服务台查询跟踪器的 Excel 工具。我想,一旦单击命令按钮,将内容从文本框复制到另一个工作表行。如果我重复该任务,文本框内容应保存在同一行的下一个空单元格中。
I used this macro:
我使用了这个宏:
Private Sub CommandButton1_Click()
TextBox1.Text = ""
TextBox1.Copy
'TextBox2.Copy
'TextBox3.Copy
Range("A2").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
End Sub
回答by Jean-Fran?ois Corbett
You really only need one line of code in your sub:
你真的只需要在你的 sub 中写一行代码:
Private Sub CommandButton1_Click()
Range("A2").End(xlDown).Offset(1, 0).Value = TextBox1.Text
End Sub
Even though you don't say so, it looks like you want the textbox to be cleared as well. If so, then add TextBox1.Text = ""one line before End Sub.
即使您不这么说,看起来您也希望清除文本框。如果是这样,则TextBox1.Text = ""在End Sub.

