View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Matt McQueen Matt McQueen is offline
external usenet poster
 
Posts: 23
Default Entering data into arrays

Folks,

I have a set of data like this:

1 Dave
3 Matt
2 Bill
4 Steve

I wanted to enter this data into an array, and assign it an address within
that array based on the number associated with each name. Hence 1 = Dave, 2 =
Bill etc. However the output seems to miss out the second data point. You end
up with:

1 Dave
2
3 Matt
4 Steve

Does data-entry into an array in VBA have to be sequential? The code I was
using was:

Sub test()
Dim testname(4)

For i = 1 To 4

testname(Cells(i, 1).Value) = Cells(i, 2).Value
Cells(i, 3).Value = testname(i)

Next i

End Sub

With the data in columns A and B in the spreadsheet. Appreciate it if
someone can spot the problem.

Cheers,

Matt