subscript out of range (help)

G

Guest

I am trying to simplify some code i use at work by using array's. This is
just a sample or test code that i put together. I keep getting a "subscript
out of range" error inside the first For Next loop. It will display the
inputbox asking for the first name, but once that is entered, i get the
error. what am i doing wrong?

Dim asi19Names() As String
Dim NoofPeople As Integer, _
i As Long

NoofPeople = InputBox(Prompt:="How many people working reports today",
Title:="How Many")

Range("A1").Select
Selection.Value = NoofPeople

For i = 0 To NoofPeople - 1
asi19Names(i) = InputBox(Prompt:="First name of worker"
Title:="Employee's")
Next i

Range("B1").Select

For i = 0 To NoofPeople - 1
Selection.Value = asi19Names(i)
Cells(1, 0).Select
Next i

End Sub
 
D

Dave Peterson

You never gave any dimensions to that array.

Still with no validation...

Dim asi19Names() As String
Dim NoofPeople As Integer, _
i As Long


NoofPeople = InputBox(Prompt:="How many people working reports today", _
Title:="How Many")

redim asil9names(0 to noofpeople - 1)

.....

======
Although, it would make more sense to me to use counting numbers:

redim asil9names(1 to noofpeople)

....

For i = lbound(noofpeople) To ubound(noofpeople)
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top