Tuesday, July 6, 2010

How to split cells into multiple rows or columns

Software Environment
Version:4.0.1
Edition:Excel

Effect image

Example code

<SelectRange("A1","Sheet1","Book1.xls")>

For(10)
$TempValue$=<ReadCell()>
$1$=<TextSearch($TempValue$,",")>
$value$=<TextExtract($TempValue$,1,$1$)>
$value$=<TextTrimRight($value$,1)>
<MoveColumn("Right",2)>
<WriteCell($value$)>
$2$=<TextSearch($TempValue$,",","nocase",2)>
$num$=<Sub($2$,$1$)>
$value$=<TextExtract($TempValue$,$1$,$num$)>
$value$=<TextTrimLeft($value$,1)>
<MoveColumn()>
<WriteCell($value$)>
$value$=<TextExtract($TempValue$,$2$)>
$value$=<TextTrimLeft($value$,1)>
<MoveColumn()>
<WriteCell($value$)>
<MoveColumn("Left",4)>
<MoveRow()>
Next


Code explanation
SelectRange("A1","Sheet1","Book1.xls")>; Select the first cell of the cells need to be processed

For(10); Loop 10 times

$TempValue$=<ReadCell()>; Get the text from the selected cell need to be processed

$1$=<TextSearch($TempValue$,",")>; Get the first position of "," symbol in the text

$value$=<TextExtract($TempValue$,1,$1$)>; Get the characters from the first character to the position of "," symbol in the text

$value$=<TextTrimRight($value$,1)>; Trim a of character from the right hand side of the text to extract.

<MoveColumn("Right",2)>; Move the cursor to right two cells

<WriteCell($value$)>; Write the processed text into the cell selected by cursor

$2$=<TextSearch($TempValue$,",","nocase",2)>; Get the second position of "," symbol in the text

$num$=<Sub($2$,$1$)>; Get the number of characters between the first "," symbol and the second "," symbol in the text

$value$=<TextExtract($TempValue$,$1$,$num$)>; Get $num$ characters from the first position of "," symbol in the text

$value$=<TextExtract($TempValue$,$2$)>; Get the remaining characters from the second position of "," symbol in the text

<MoveColumn("Left",4)>; Move the cursor to left four cells

Related operations
Text search

Text extract

Text trim right

Text trim left