Excel VBA: Range to String Array in 1 step -


i know can take range of cells , slap them variant array want work string array (because it's single-dimensional , takes less memory variant array).

is there way automatically convert range string array?

right using function take range , save values in variant array, convert variant array string array. works nice , i'm looking way go directly range string array. appreciated.

function rangetoarray(byval my_range range) string()  dim varray variant dim sarray() string dim long  varray = my_range.value redim sarray(1 ubound(varray))  = 1 ubound(varray)     sarray(i) = varray(i, 1) next  rangetoarray = sarray()  end function  

update: it's looking there no way skip step of throwing data variable array first before converting single-dimensional string array. shame if it's true (even if doesn't take effort, ultra-optimize hoping there way skip step). i'll close question in few days if no solution presents itself. helpful comments, guys!

update2: answer goes simon put in great effort (so did else) , utlimately pointed out it's indeed impossible go range string array in 1 shot. thanks, everyone.

how about...

public function rangetostringarray(therange excel.range) string()      ' values variant array     dim variantvalues variant     variantvalues = therange.value      ' set string array them     dim stringvalues() string     redim stringvalues(1 ubound(variantvalues, 1), 1 ubound(variantvalues, 2))      ' put them in there!     dim columncounter long, rowcounter long     rowcounter = ubound(variantvalues, 1) 1 step -1        columncounter = ubound(variantvalues, 2) 1 step -1            stringvalues(rowcounter, columncounter) = cstr(variantvalues(rowcounter, columncounter))        next columncounter     next rowcounter      ' return string array     rangetostringarray = stringvalues  end function 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -