parse data separately in cells with vbNewLine

stephfr

New Member
Joined
Aug 17, 2011
Messages
39
Hi

I need to extract data from an excel file (using VBA) to another file. However, the data is stored in one cell with a line break to separate each item.

I need to be able to read each string within the cell so that I can extract the mobile numbers (starting with 06 or 07). For the first number in the string, I'm OK (I can use the left function) but I need to be also able to read the second number that is after the NewLine.

When I create the original data in the cell (and add the new line, I do this: Tel1 & vbNewLine & Tel2). Now I need to be able to read each one individually.

Can anyone help???

Thanks
Steph


For example:

Cell G2:
04 79 12 09 00
06 47 86 78 99


<colgroup><col></colgroup><tbody>
</tbody>
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You can make an array that contains the individual sub-strings:

Code:
Sub dural()
Dim s As String
s = Range("G2").Value
ary = Split(s, vbNewLine)
End Sub
 
Upvote 0
Hi

I need to extract data from an excel file (using VBA) to another file. However, the data is stored in one cell with a line break to separate each item.

I need to be able to read each string within the cell so that I can extract the mobile numbers (starting with 06 or 07). For the first number in the string, I'm OK (I can use the left function) but I need to be also able to read the second number that is after the NewLine.

When I create the original data in the cell (and add the new line, I do this: Tel1 & vbNewLine & Tel2). Now I need to be able to read each one individually.

Can anyone help???

Thanks
Steph


For example:

Cell G2:
04 79 12 09 00
06 47 86 78 99


<TBODY>
</TBODY>

I am a little confused at what you want from G2... can you show us the result you expect to put in the new file?

Also, what is the new file... a text file, a worksheet, something else?
 
Upvote 0
I am a little confused at what you want from G2... can you show us the result you expect to put in the new file?

Also, what is the new file... a text file, a worksheet, something else?

Hi Rick

The new file is a worksheet (which I have no problem with).

My example, is column G contains a list of phone numbers for given contacts. When there are several phone numbers for the same contact, they are in the same cell separated by a vbNewLine.

What I need is to only extract the data where at least one of the telephone numbers begins with 06 or 07

Here is an extract of a column that I would expext in the result

TÉLVILLE
06 67 58 90 70PARIS
06 75 42 53 36MARSEILLE
06 62 71 18 24 LE PERREUX-SUR-MARNE
06 08 74 79 55
07 51 22 02 15
PARIS
06 07 18 48 48ST ESTEBEN
06 66 40 04 80MAUGUIO CARNON

<colgroup><col><col></colgroup><tbody>
</tbody>


Thanks :)
Steph

<colgroup><col></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top