将dim细胞文本值作为控件(excel dim cell text value as controls)

499 IT屋

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.

enter image description here

我遇到麻烦我的宏。我在表单上有一个按钮和几个复选框,我正在尝试编写一个代码,当我点击按钮时,它将检查范围("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中输入正确的名称



enter image description here


本文地址:IT屋 » 将dim细胞文本值作为控件