1

I am trying to get the value of a textbox and save it to a string array by clicking a button. I am getting a syntax error on the name(0) = TextBox1.Text line. I will be making it a dynamic array once I figure out how to do it (that's why I have a num variable as well because the button can be clicked multiple times).

Am I doing something wrong here?

Private Sub CommandButton1_Click()
   Dim name(10) As String
   Dim num As Integer

   ' Debug.Print TextBox1.Text

   name(0) = TextBox1.Text
End Sub

1 Answer 1

2

'Name' is a built in name for excel.

Try:

Private Sub CommandButton1_Click()
   Dim testArray(1 to 11) As String
   Dim num As Integer

   ' Debug.Print TextBox1.Text

   testArray(1) = TextBox1.Text
End Sub

EDIT: Changed the name of the array.

Sign up to request clarification or add additional context in comments.

3 Comments

Hmm. could you printscreen the error and add it to your question please?
or wait, test this first: change the word 'name' it could be that it is a built in excel function or something and that could be causing the error
OMG! You're right. name is a built-in function. Time to properly name my variable now. Thanks a lot!!!!

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.