From: Dana DeLouis on
On 12/16/2009 11:39 AM, Damil4real wrote:
> How can I use a macro to extract only the first batch of numbers from
> the following type of info?
>
> Examples:
>
> 01458-MODE
> 1548-JUNE
> 1245-NOD
> 01054-MORNING
> 00154-JUNE
> 55145-55145
>
> Result should be:
>
> 01458
> 1548
> 1245
> 01054
> 00154
> 55145
> --------------------
>
> I only need the first batch of numbers before the "-" sign. There will
> always be this sign "-" separating the two batch of data.
>
> Thanks!

If you don't need the leading zero's...

Sub Demo()
Debug.Print Val("01054-MORNING")
Debug.Print Val("00154-JUNE")
Debug.Print Val("55145-55145")
End Sub

Returns:
1054
154
55145

Perhaps format with leading zero's if you need to.

= = = = = = =
HTH :>)
Dana DeLouis
From: helene and gabor on
=left(a1,find("-",a1,1)-1)

assuming:
text to be extracted in A1
your letters start in column 2 (they do)

Good Luck!

Gabor Sebo


"Dana DeLouis" <delouis(a)bellsouth.net> wrote in message
news:uHLKbMxwKHA.5940(a)TK2MSFTNGP02.phx.gbl...
> On 12/16/2009 11:39 AM, Damil4real wrote:
>> How can I use a macro to extract only the first batch of numbers from
>> the following type of info?
>>
>> Examples:
>>
>> 01458-MODE
>> 1548-JUNE
>> 1245-NOD
>> 01054-MORNING
>> 00154-JUNE
>> 55145-55145
>>
>> Result should be:
>>
>> 01458
>> 1548
>> 1245
>> 01054
>> 00154
>> 55145
>> --------------------
>>
>> I only need the first batch of numbers before the "-" sign. There will
>> always be this sign "-" separating the two batch of data.
>>
>> Thanks!
>
> If you don't need the leading zero's...
>
> Sub Demo()
> Debug.Print Val("01054-MORNING")
> Debug.Print Val("00154-JUNE")
> Debug.Print Val("55145-55145")
> End Sub
>
> Returns:
> 1054
> 154
> 55145
>
> Perhaps format with leading zero's if you need to.
>
> = = = = = = =
> HTH :>)
> Dana DeLouis
>