vba - Putting separate ranges into 2D array -


i'm trying 2d array of size [x][3] filled. x size of sheet (number of rows) , there 3 columns interested in. columns not near each other, instance arr[i][0] should filled column aa, arr[i][1] should come column k, , arr[i][2] needs columns l.

i tried assigning following way, got error in array value assignment.

any on appreciated!

code:

sub soc_work() 'trying sort each of disciplines further, stage of construction  dim ar_soc() variant dim int_numrows long dim i_counter long dim j_counter long dim lite range  application.calculation = xlcalculationmanual application.screenupdating = false  sheets("aveva_pbom_parts").select   'redimension array size amount of parts in pbom int_numrows = activesheet.usedrange.rows.count - 1 redim ar_soc(int_numrows, 3)  'now assignt range array space lite = range("aa2", range("aa2").end(xldown))   ar_soc[][1]=lite    end sub 

is there way without looping through entire column?

as described in comments, can fill 3 2-d arrays. can populate fourth array 3 arrays, below.

sub populatearray()     dim arrcolone() variant, arrcoltwo() variant, arrcolthree() variant     dim arralldata() variant     dim long      arrcolone = range("a2:a" & lrow(1)) 'amend column number     arrcoltwo = range("d2:d" & lrow(4))     arrcolthree = range("g2:g" & lrow(7))      redim arralldata(1 ubound(arrcolone, 1), 2) variant     = 1 ubound(arrcolone, 1)         arralldata(i, 0) = arrcolone(i, 1)         arralldata(i, 1) = arrcoltwo(i, 1)         arralldata(i, 2) = arrcolthree(i, 1)     next end sub  public function lrow(colnum integer) long     lrow = cells(rows.count, colnum).end(xlup).row end function 

the above require 3 columns same length (otherwise populating last array not work); due fourth array being redimensioned contain number of elements contained in first array.

testing 250,000 rows of data, fourth array populated in 0.43 seconds.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -