2017-03-22 48 views
0

我有10個用戶窗體控件,名稱爲Account1到Account10,默認爲Visible = False。我正在嘗試創建一個函數以按照升序數字順序取消隱藏控件。用於隱藏用戶窗體控件的VBA函數

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代碼?

+5

'Me.Controls(「賬戶」及數)。可見= TRUE; – Comintern

+2

考慮*創建*在運行時,而不是隱藏/取消隱藏文本框他們。 –

回答

0

添加到@共產國際的答案,解決辦法是:

For i = 1 To 10 
    Me.Controls("Account" & i).Visible = True 
Next i