excel dim cell text value as controls

泄露秘密 提交于 2019-12-11 08:16:39

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/22765856/excel-dim-cell-text-value-as-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!