Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default subscript out of range (help)

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default subscript out of range (help)

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)
...

edluver wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default subscript out of range (help)

As posted, you didn't dimension the string

"edluver" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
subscript out of range new! tigoda Excel Programming 2 November 15th 06 05:26 PM
Subscript out of Range Jon[_22_] Excel Programming 4 April 6th 06 11:24 PM
subscript out of range lvcha.gouqizi Excel Programming 5 October 31st 05 07:56 PM
Subscript out of range.... Edgar Thoemmes[_4_] Excel Programming 4 January 13th 05 02:06 AM
Subscript out of range Bill Murphy Excel Programming 1 August 5th 04 08:52 AM


All times are GMT +1. The time now is 06:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"