Excel: Space Parsing Macro for Versions 1.50 and EarlierLast reviewed: November 1, 1994Article ID: Q51965 |
SUMMARYOutlined below is a Microsoft Excel macro for parsing spaces. This macro takes data from a single cell and "parses" it among several cells. For example, a cell containing the information "data data data data" would be separated into four cells with the Space Parsing macro. Note: Excel version 2.20 has a built-in parsing command.
MORE INFORMATIONThe Space Parsing macro assumes that you have two or more spaces between the items you want parsed into separate cells. Below is an example of how the Space Parsing macro separates data. Assume that the original data is as follows:
A ---------------- 1 | 234 234 | ---------------- 2 | 12 12 12 | ---------------- 3 | 23 23 | ----------------If you place the cursor in cell A1 and press COMMAND+OPTION+A to run the Space Parsing macro, the result is the following:
| A | B | C | ------------------------------- 1 | 234 | 234 | | ------------------------------- 2 | 12 | 12 | 12 | ------------------------------- 3 | | 23 | 23 | -------------------------------To create the Space Parsing macro, do the following:
1 | Names | SPACEPARSER 2 | | =ECHO(FALSE) 3 | Firstspace | =SEARCH(" ",DEREF(ACTIVE.CELL()),1) 4 | | =IF(ISERROR(Firstspace),GOTO(Next)) 5 | | =SET.NAME("endspace",DEREF(Firstspace)) 6 | Startloop | =IF(SEARCH(" ",DEREF(ACTIVE.CELL()),endspace+1)= | | (endspace+1),SET.NAME("endspace",endspace+1)) 7 | | =IF(Startloop<>FALSE(),GOTO(Startloop)) 8 | Secondhalf | =MID(DEREF(ACTIVE.CELL()),endspace+2, | | (1+LEN(ACTIVE.CELL())-endspace)) 9 | | =SELECT("rc[1]") 10 | | =FORMULA(Secondhalf) 11 | | =SELECT("rc[-1]")12 | Firsthalf | =MID(DEREF(ACTIVE.CELL()),1,DEREF(Firstspace)-1) 13 | | =FORMULA(Firsthalf) 14 | | =SELECT("rc[1]") 15 | | =GOTO(SPACEPARSER) 16 | Next | =SELECT("rc[-"&COLUMN(ACTIVE.CELL())-1&"]") 17 | | =SELECT("r[1]c") 18 | | =IF(NOT(AND(TYPE(ACTIVE.CELL())=1, | | LEN(ACTIVE.CELL())=0)),GOTO(Firstspace)) 19 | | =RETURN()
|
KBCategory: kbother
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |