Excel VBA - 活动单元格中TextBox的文本 [英] Excel VBA - Text from TextBox in the active cell

查看:855
本文介绍了Excel VBA - 活动单元格中TextBox的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个TextBox和一个CommandButton构建一个简单的UserForm,它通过在一个特殊的列(例如,列A,单元格A1)中单击空单元格在工作表内。当我输入文本并按下按钮时,输入的文本应该粘贴到活动单元格(A1)中。



建立UserForm不是问题,而是背后的动作。



你们有一个想法如何解决这个问题吗?还是更好的代码片段?



提前感谢!

解决方案

以下是一段代码,当您点击单元格时将运行

  Private Sub Worksheet_SelectionChange(ByVal Target As Range)
如果Selection.Count = 1然后
如果不相交(目标,范围(A1))是没有,然后
'userform的名称。显示
结束如果
结束如果
结束Sub

代码中有一个注释,你需要你的userform的名字,然后是。显示



输入文字,可以按照您的建议说A1:

  Private Sub CommandButton1_Click()

TextValue = TextBox1.Text

[A1] .Value = TextValue

End Sub
pre>

将$ code> CommandButton1 和 TextBox1 命名他们(如果你命名他们,你应该)



如果你需要任何澄清只要问


I would like to build a simple UserForm with a TextBox and a CommandButton, which opens itself by clicking inside a empty cell in a special column (for example in the column A, the cell A1) inside the worksheet. When I enter a text and hit the button, the entered text should be pasted in the active cell (A1).

The building of the UserForm is not the problem, but the actions which are behind it.

Do you guys have an idea how to solve this? Or even better pieces of code?

Thanks in advance!

解决方案

Here is a piece of code that will run when you click a cell

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Selection.Count = 1 Then
        If Not Intersect(Target, Range("A1")) Is Nothing Then
            'name of userform .Show
        End If
    End If
End Sub

Where the code has a comment you need the name oof your userform and then .Show

Entering the text into, lets say A1 as you suggested, would be:

Private Sub CommandButton1_Click()

TextValue = TextBox1.Text

[A1].Value = TextValue

End Sub

Change the CommandButton1 and TextBox1 to whatever you named them(if you named them, which you should)

If you need anything clarified just ask

这篇关于Excel VBA - 活动单元格中TextBox的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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