Share via

reference text inside a text box

Anonymous
2013-10-24T16:31:57+00:00

I create textboxes through the variable x on a blank userform except for a command button.  How do I reference the contents in let's say textbox 3 which has the word "hello" in it typed in by the user? 

Thanks for the help.

Sub gggg()

    Dim a As Integer

    Dim cCntrl As Control

    Dim x As Long

    x = InputBox("number")

    For i = 1 To x

            Set cCntrl = UserForm1.Controls.Add("Forms.TextBox.1", "TextBox" & i, True)

            With cCntrl

                .Width = 150

                .Height = 25

                .Top = 2 + (i * 40)

                .Left = 10

                .ZOrder (0)

            End With

    Next i

UserForm1.Show

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2013-10-26T12:25:10+00:00

    For example

        Dim strText As String

        strText = UserForm1.TextBox3.Value

    or

        Dim strText As String

        Dim i As Long

        i = 3

        strText = UserForm1.Controls("TextBox" & i).Value

    Was this answer helpful?

    0 comments No comments