How do I reference the checkbox of the userform with a variable

五迷三道 提交于 2019-12-25 09:49:06

问题


Could anyone tell me how to reference a checkbox of the userform with a variable?

For example I have something like these,

   if UserForm1.checkbox1.Value
   if UserForm1.checkbox2.Value 
   if UserForm1.checkbox3.Value

I have to check nearly 40 to 50 checkboxes. But writing the 40 to 50 statements like these is time consuming and also makes a bigger code.

So I was kinda thinking to loop through them:

 For i = 1 To 50 
   UserForm1.checkbox & i .Value
 Next i

Something like that. I didn't find too much but I found it at the end. This is the link http://www.ozgrid.com/forum/showthread.php?t=43358 and the answer was like these,

UserForm1.Shapes("Checkbox" & i).Value

But it isn't working. Does any one know the way to do it? Is it possible? Any help is greatly appreciated.


回答1:


UserForm1.Controls("Checkbox" & i).Value 


来源:https://stackoverflow.com/questions/7966611/how-do-i-reference-the-checkbox-of-the-userform-with-a-variable

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