![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | populating two dimensional array with excel data Hi, I'm looking for an efficient way to populate a two dimensional array. The first cell of each row contains the First Name and the second cell has the Last Name. I'm ok up to the part where I actually need to read the data in The code I have for reading the data into the array works but it is just awful: 'loop reading each spreadsheet element into the array n = 0 'counter for array element position intRow = 1 intCol = 1 Do Until objExcel.Cells(intRow,intCol).Value = "" Fullname(n,0) = objExcel.Cells(intRow, intCol).Value intRow = intRow + 1 n = n + 1 Loop intRow = 1 intCol = 2 n = 0 Do Until objExcel.Cells(intRow,intCol).Value = "" Fullname(n,1) = objExcel.Cells(intRow, intCol).Value intRow = intRow + 1 n = n + 1 Loop There has to be a better way. Can someone show me? Thanks in Advance |
My System Specs![]() |
| | #2 (permalink) |
| | RE: populating two dimensional array with excel data For row = 1 to 999999 If objExcel.Cells(row, 1).Value = "" Then Exit For Fullname(row-1,0) = objExcel.Cells( row, 1).Value Fullname(row-1,1) = objExcel.Cells( row, 2).Value Next I should point out, though, that VBS typically works better with the columnd and rows reversed from what you are using. The reason for that is that you can do ReDim Preserve arrayName( existingNumberOfColumns, newNumberOfRows ) to easily add rows to an array. With ReDim Preserve, only the *LAST* dimension can be changed in the ReDim. If this is strictly for your own use and you KNOW you won't need to expand that FullName array, it won't matter, but consider it for the future. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: populating two dimensional array with excel data If there are only 2 columns of data on the sheet and it's a contiguous block: Dim arrData arrData = objExcel.Cells(1,1).CurrentRegion.Value arrData will be a 2-D array. Tim. "Mecha77" <Mecha77@xxxxxx> wrote in message news:1A97F690-57AC-42D8-911B-BE5C79ADF61F@xxxxxx Quote: > Hi, > I'm looking for an efficient way to populate a two dimensional array. The > first cell of each row contains the First Name and the second cell has the > Last Name. I'm ok up to the part where I actually need to read the data in > > The code I have for reading the data into the array works but it is just > awful: > > 'loop reading each spreadsheet element into the array > n = 0 'counter for array element position > intRow = 1 > intCol = 1 > > > Do Until objExcel.Cells(intRow,intCol).Value = "" > > Fullname(n,0) = objExcel.Cells(intRow, intCol).Value > intRow = intRow + 1 > n = n + 1 > > Loop > > intRow = 1 > intCol = 2 > n = 0 > > Do Until objExcel.Cells(intRow,intCol).Value = "" > > Fullname(n,1) = objExcel.Cells(intRow, intCol).Value > intRow = intRow + 1 > n = n + 1 > > Loop > > There has to be a better way. Can someone show me? > > Thanks in Advance > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: populating two dimensional array with excel data Thank you to Old Pedant and Tim for your help "Tim Williams" wrote: Quote: > If there are only 2 columns of data on the sheet and it's a contiguous > block: > > Dim arrData > arrData = objExcel.Cells(1,1).CurrentRegion.Value > > arrData will be a 2-D array. > > Tim. > > > "Mecha77" <Mecha77@xxxxxx> wrote in message > news:1A97F690-57AC-42D8-911B-BE5C79ADF61F@xxxxxx Quote: > > Hi, > > I'm looking for an efficient way to populate a two dimensional array. The > > first cell of each row contains the First Name and the second cell has the > > Last Name. I'm ok up to the part where I actually need to read the data in > > > > The code I have for reading the data into the array works but it is just > > awful: > > > > 'loop reading each spreadsheet element into the array > > n = 0 'counter for array element position > > intRow = 1 > > intCol = 1 > > > > > > Do Until objExcel.Cells(intRow,intCol).Value = "" > > > > Fullname(n,0) = objExcel.Cells(intRow, intCol).Value > > intRow = intRow + 1 > > n = n + 1 > > > > Loop > > > > intRow = 1 > > intCol = 2 > > n = 0 > > > > Do Until objExcel.Cells(intRow,intCol).Value = "" > > > > Fullname(n,1) = objExcel.Cells(intRow, intCol).Value > > intRow = intRow + 1 > > n = n + 1 > > > > Loop > > > > There has to be a better way. Can someone show me? > > > > Thanks in Advance > > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| how can i determine the excel rows that contain data | PowerShell | |||
| Re: data into excel | VB Script | |||
| Re: data into excel | VB Script | |||
| excel data | Vista General | |||
| 2 dimensional array of objects | VB Script | |||