将dim细胞文本值作为控件 [英] excel dim cell text value as controls

查看:631
本文介绍了将dim细胞文本值作为控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到麻烦我的宏。我在表单上有一个按钮和几个复选框,我正在尝试编写一个代码,当我点击按钮时,它将检查范围(A1)。文本,取得该文本(在这种情况下为 checkbox1),我想这样说:

  questionnaire =范围(A1)。文本
问卷调查值=范围(A2)价值

我想要的是,当我在A1中写一个控制名称时,当我点击按钮时,该控件将取值为A2。问题是我不知道我应该做什么DIM问卷。请帮助



谢谢

解决方案

尝试这个

  Private Sub CommandButton1_Click()
CB = Sheets(3).Range(A1)。value
CBVal = (3).Range(A2)。值

对于每个contr在UserForm1.Controls
如果TypeName(contr)=CheckBox和contr.Name = CB然后
contr.Value = CBVal
结束If
下一个
End Sub



确保您在A1中输入正确的名称




I am having trouble with my macro. I have a button and a few check boxes on a form, i am trying to write a code that when i click the button it will check the range("A1").text, after take that text (which in this case is "checkbox1") and i want to say something like this:

questionnaire = Range("A1").Text
questionnaire.Value = Range("A2").Value

since i have many checkboxes as mentioned earlier, i want that when i write a certain controls name in "A1", when i click the button, that control will take the value in "A2". the problem is i do not know what i should DIM questionnaire as. please help

Thank you

解决方案

Try this

Private Sub CommandButton1_Click()
    CB = Sheets(3).Range("A1").Value
    CBVal = Sheets(3).Range("A2").Value

    For Each contr In UserForm1.Controls
        If TypeName(contr) = "CheckBox" And contr.Name = CB Then
            contr.Value = CBVal
        End If
    Next
End Sub

Make sure you type in the correct Name in A1.

这篇关于将dim细胞文本值作为控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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