1

I have 10 UserForm Controls with Names Account1 to Account10 that are defaulted as Visible = False. I am trying to create a Function to unhide the Controls in ascending numeric order.

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

How can I simplify this VBA code?

2
  • 5
    Me.Controls("Account" & number).Visible = True Commented Mar 22, 2017 at 14:52
  • 2
    Consider creating textboxes at run-time instead of hiding/unhiding them. Commented Mar 22, 2017 at 14:54

1 Answer 1

1

Adding to @Comintern's answer, solution is:

For i = 1 To 10
    Me.Controls("Account" & i).Visible = True
Next i
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.