将内容从文本框复制并粘贴到工作表单元格范围? [英] Copy and paste content from a textbox to a worksheet cell range?

查看:169
本文介绍了将内容从文本框复制并粘贴到工作表单元格范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发VBA项目,以自动化服务台查询跟踪器的Excel工具。我想要的是,一旦命令按钮被点击,将内容从文本框复制到另一个工作表行。如果我重复任务,则文本框内容应保存在同一行的下一个空单元格中。



我使用这个宏:

  Private Sub CommandButton1_Click()
TextBox1.Text =
TextBox1.Copy
'TextBox2.Copy
'TextBox3.Copy
Range(A2)。选择
Do
如果IsEmpty(ActiveCell)= False然后
ActiveCell.Offset(1,0)。选择
End If
循环直到IsEmpty(ActiveCell)= True
End Sub


  Private Sub CommandButton1_Click( )
Range(A2)。End(xlDown).Offset(1,0).Value = TextBox1.Text
End Sub

即使你不这么说,看起来你也希望文本框也被清除。如果是,则在 End Sub 之前添加 TextBox1.Text =


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.

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

解决方案

You really only need one line of code in your 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.

这篇关于将内容从文本框复制并粘贴到工作表单元格范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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