Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Entering data into arrays
Your array is populated just fine. Your issue is with when you try to write
the values. The second array item is not populated until your counter is at 3. Problem is you tried to write it at 2 before it was populated... try this... Sub test() Dim testname(4) As String Dim i As Integer For i = 1 To 4 testname(Cells(i, 1).Value) = Cells(i, 2).Value Next i For i = 1 To 4 Cells(i, 3).Value = testname(i) Next i End Sub -- HTH... Jim Thomlinson "Matt McQueen" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
transfering data in another column entering more sorted data | Excel Worksheet Functions | |||
Reading data arrays from multiple data files in excel | Excel Discussion (Misc queries) | |||
Data Access Efficiency: Arrays versus Worksheet Data | Excel Programming | |||
Working with ranges in arrays... or an introduction to arrays | Excel Programming | |||
Arrays - declaration, adding values to arrays and calculation | Excel Programming |