excel - Expand on recorded "Text To Column" macro -
i trying (as learning functional macro) turn recorded macro following function.
i error "no data selected parse"
i think problem selection.texttocolumns destination:=cells(1, (cnum + 1)).select
in second sub. don't know if "idel"
problem way have written have not got past how change destination:=range("i1")
where:
cnum
column parsed
icol
number of columns insert
idel
parsing delimiter
isn
in sheet number
any insight helpful
this fixed version2: (this last version ( did not know put array in "ftexetocolumn" gave try , worked)
sub texetocolumn() '1st column parsed '2nd number of columns insert '3rd parsing delimiter '4th sheet number 'array set new col header names, add many name 2nd parameter equal ftexetocolumn "8", "3", "[", "2", array("new col name1", "new col name2", "new col name3") end sub sub ftexetocolumn(cnum long, icol long, idel string, isn long, headers variant) 'cnum column parsed 'icol number of columns insert 'idel parsing delimiter 'isn sheet number dim long dim basewks worksheet '~~> set sheet here sheets(isn).select '~~>adding columns colx = 1 icol step 1 columns(cnum + colx).insert shift:=xltoright next '~~>column parsed columns(cnum).select '~set destination range here selection.texttocolumns destination:=cells(1, (cnum + 1)), datatype:=xldelimited, _ textqualifier:=xlnone, consecutivedelimiter:=false, tab:=false, _ semicolon:=false, comma:=false, space:=false, other:=true, otherchar _ :=idel, fieldinfo:=array(array(1, 1), array(2, 1)), trailingminusnumbers:=true '~~>delete original column columns(cnum).delete 'set header names set basewks = thisworkbook.worksheets(isn) = lbound(headers) ubound(headers) basewks.cells(1, + cnum) = headers(i) next end sub
op correctly identified 2 problems:
i) selection.texttocolumns destination:=cells(1, (cnum + 1)).select and
ii) idel
for former .select
syntax error (by time of “set destination range” column has been selected) , latter idel
has been defined [
string whereas use of ”idel”
work if required delimiter i
(since single character permitted delimiter text columns).
the fix, reflected in op, delete .select
, quotation marks around idel
.
Comments
Post a Comment