Extract number from two delimiter

B

Bill Howland

Hello,

I have several text of the following format in a column

int a;
char ball[3];
long c1 [300 ];
char d;

I would like to extract the number between two '[' ']' square
brackets and store it in an adjacent column. If a text does not have
the the square brackets, I would like to have number 1 stored in the
adjacent column. There could be also
spaces in between the brackets (row 3 shows an example).

I would appreciate if anybody can help me using a cell formula to
achieve this.

Thanks in advance,
Bill
 
P

Peo Sjoblom

One way

=IF(ISNUMBER(FIND("[",A1)),--MID(A1,FIND("[",A1)+1,FIND("]",A1)-FIND("[",A1)
-1),1)

--
Regards,

Peo Sjoblom

(No private emails please, for everyone's
benefit keep the discussion in the newsgroup/forum)
 
P

Peo Sjoblom

An easier way would be to use data>text to columns, use one bracket as the
first delimiter and do not import the column
without numbers, then repeat for the other delimiter, that would give you
numbers and empty cells, then select the range,
press F5 and select special and blanks, then type 1 and ctrl + enter and you
are done

--
Regards,

Peo Sjoblom

(No private emails please, for everyone's
benefit keep the discussion in the newsgroup/forum)



Peo Sjoblom said:
One way

=IF(ISNUMBER(FIND("[",A1)),--MID(A1,FIND("[",A1)+1,FIND("]",A1)-FIND("[",A1)
-1),1)

--
Regards,

Peo Sjoblom

(No private emails please, for everyone's
benefit keep the discussion in the newsgroup/forum)



Bill Howland said:
Hello,

I have several text of the following format in a column

int a;
char ball[3];
long c1 [300 ];
char d;

I would like to extract the number between two '[' ']' square
brackets and store it in an adjacent column. If a text does not have
the the square brackets, I would like to have number 1 stored in the
adjacent column. There could be also
spaces in between the brackets (row 3 shows an example).

I would appreciate if anybody can help me using a cell formula to
achieve this.

Thanks in advance,
Bill
 
B

Bill Howland

Thanks very much. It worked great!

Regards
Bill

Peo Sjoblom said:
One way

=IF(ISNUMBER(FIND("[",A1)),--MID(A1,FIND("[",A1)+1,FIND("]",A1)-FIND("[",A1)
-1),1)

--
Regards,

Peo Sjoblom

(No private emails please, for everyone's
benefit keep the discussion in the newsgroup/forum)



Bill Howland said:
Hello,

I have several text of the following format in a column

int a;
char ball[3];
long c1 [300 ];
char d;

I would like to extract the number between two '[' ']' square
brackets and store it in an adjacent column. If a text does not have
the the square brackets, I would like to have number 1 stored in the
adjacent column. There could be also
spaces in between the brackets (row 3 shows an example).

I would appreciate if anybody can help me using a cell formula to
achieve this.

Thanks in advance,
Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top