excel - Separate characters by dashes in vba -


i trying separate characters (-)dashes in vba, paste column b. in column have tom-jay-moe-xray. if want split , paste 4 different column column b=tom, c=jay,so on. here code , image understand better.

enter image description here

sub x()     dim sheet worksheet     set sheet = activeworkbook.worksheets("sheet1")     x = 1 sheet.range("a" & sheet.rows.count).end(xlup).row         sheet.range("a", "b", "c", "d" & x) = instr(1, sheet.cells(x, 1), "-")     next x end sub 

you can this:

with sheets("sheetname")     dim lr long     lr = .range("a" & .rows.count).end(xlup).row     .range("a1:a" & lr).texttocolumns destination:=.range("b1") _         , datatype:=xldelimited, other:=true, otherchar:="-" end 

there built-in functionality in excel separate delimited text, texttocolumns.
need use separate string if have 1 delimiter.

actually, if want data in column evaluated, don't need check last row value. below work fine.

with sheets("sheetname")     .range("a:a").texttocolumns destination:=.range("b1") _         , datatype:=xldelimited, other:=true, otherchar:="-" end 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -