我有10个UserForm控件,名称为Account1到Account10,默认为Visible = False。我正在尝试创建一个函数来按升序数字顺序取消隐藏控件。
Private Sub AddButton_Click()
Select Case CountTextBox.Value
Case 1
Account1.Visible = True
Case 2
Account2.Visible = True
Case 3
Account3.Visible = True
Case 4
Account4.Visible = True
Case 5
Account5.Visible = True
Case 6
Account6.Visible = True
Case 7
Account7.Visible = True
Case 8
Account8.Visible = True
Case 9
Account9.Visible = True
Case 10
Account10.Visible = True
End Select
End Sub
如何简化此VBA代码?
答案 0 :(得分:1)
添加到@ Comintern的答案,解决方案是:
For i = 1 To 10
Me.Controls("Account" & i).Visible = True
Next i