Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3
Default Extract a text string based on character

I am trying to extract a model number from the title.

Brand New D-Link AirPlus G DI-524 Wireless Router;

I need to extract the DI-524. All of the model numbers have the - charcter,
but are different lengths. How would I use the mid function, not knowing the
length and exact position?

For instance, here is another title:

**New** Acer TravelMate TM4720-6218, 2.2GHz Core 2 Duo;

I need the TM4720-6218 extracted from the text string.

Thank you for your help!

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 345
Default Extract a text string based on character

How are you entering the title into the cell? A bit of lateral thinking - Can
the title be entered into three adjacent columns with the model number in the
middle cell - you could then, in a fourth column, concatentate the title back
into one cell!

"kgiraffa" wrote:

I am trying to extract a model number from the title.

Brand New D-Link AirPlus G DI-524 Wireless Router;

I need to extract the DI-524. All of the model numbers have the - charcter,
but are different lengths. How would I use the mid function, not knowing the
length and exact position?

For instance, here is another title:

**New** Acer TravelMate TM4720-6218, 2.2GHz Core 2 Duo;

I need the TM4720-6218 extracted from the text string.

Thank you for your help!

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Extract a text string based on character

On Thu, 13 Mar 2008 07:39:04 -0700, kgiraffa
wrote:

I am trying to extract a model number from the title.

Brand New D-Link AirPlus G DI-524 Wireless Router;

I need to extract the DI-524. All of the model numbers have the - charcter,
but are different lengths. How would I use the mid function, not knowing the
length and exact position?

For instance, here is another title:

**New** Acer TravelMate TM4720-6218, 2.2GHz Core 2 Duo;

I need the TM4720-6218 extracted from the text string.

Thank you for your help!


With the information you have given, it is not possible without manual editing.
Your description of a model number -- having the "-" character -- does not
return only model numbers. For example, in your first example, a routine that
would return words with "-"'s would also return D-Link.

If we could be guaranteed that the model designation will always be the LAST
word in the string that contains a "-", and also that there will not be an
<space within the model designation, then this UDF can be used to return it:

================================
Option Explicit
Function Model(str As String) As String
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "\b\S+-\S+\b"
If re.test(str) = True Then
Set mc = re.Execute(str)
Model = mc(mc.Count - 1)
End If
End Function
================================

To enter the UDF, <alt-F11 opens the VBEditor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Module and paste the
code above into the window that opens.

To use this, enter a formula =Model(cell_ref) into some cell where cell_ref
refers to the cell containing the string with the model number.

This algorithm could be done with worksheet formula, but it is involved and I'd
rather wait to see exactly what your specifications are, before going further.
--ron
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3
Default Extract a text string based on character

That would be great, but it is information that is downloaded from other
websites. This is how the information downloads.....I just want to alter it.
Unfortunately, it isn't always in the same spot in the text. I do
appreciate your input!

"Ron@Buy" wrote:

How are you entering the title into the cell? A bit of lateral thinking - Can
the title be entered into three adjacent columns with the model number in the
middle cell - you could then, in a fourth column, concatentate the title back
into one cell!

"kgiraffa" wrote:

I am trying to extract a model number from the title.

Brand New D-Link AirPlus G DI-524 Wireless Router;

I need to extract the DI-524. All of the model numbers have the - charcter,
but are different lengths. How would I use the mid function, not knowing the
length and exact position?

For instance, here is another title:

**New** Acer TravelMate TM4720-6218, 2.2GHz Core 2 Duo;

I need the TM4720-6218 extracted from the text string.

Thank you for your help!

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3
Default Extract a text string based on character

This worked great, Thank you!!!!

"Ron Rosenfeld" wrote:

On Thu, 13 Mar 2008 07:39:04 -0700, kgiraffa
wrote:

I am trying to extract a model number from the title.

Brand New D-Link AirPlus G DI-524 Wireless Router;

I need to extract the DI-524. All of the model numbers have the - charcter,
but are different lengths. How would I use the mid function, not knowing the
length and exact position?

For instance, here is another title:

**New** Acer TravelMate TM4720-6218, 2.2GHz Core 2 Duo;

I need the TM4720-6218 extracted from the text string.

Thank you for your help!


With the information you have given, it is not possible without manual editing.
Your description of a model number -- having the "-" character -- does not
return only model numbers. For example, in your first example, a routine that
would return words with "-"'s would also return D-Link.

If we could be guaranteed that the model designation will always be the LAST
word in the string that contains a "-", and also that there will not be an
<space within the model designation, then this UDF can be used to return it:

================================
Option Explicit
Function Model(str As String) As String
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "\b\S+-\S+\b"
If re.test(str) = True Then
Set mc = re.Execute(str)
Model = mc(mc.Count - 1)
End If
End Function
================================

To enter the UDF, <alt-F11 opens the VBEditor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Module and paste the
code above into the window that opens.

To use this, enter a formula =Model(cell_ref) into some cell where cell_ref
refers to the cell containing the string with the model number.

This algorithm could be done with worksheet formula, but it is involved and I'd
rather wait to see exactly what your specifications are, before going further.
--ron



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Extract a text string based on character

On Thu, 13 Mar 2008 16:55:01 -0700, kgiraffa
wrote:

This worked great, Thank you!!!!


Well, I'm glad it worked for you. I guess my assumptions about your data were
correct. Thanks for the feedback.
--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract text from a string ellebelle Excel Worksheet Functions 4 June 13th 07 04:25 PM
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
Extract String based on condition Send Object Command - Two attachments Excel Discussion (Misc queries) 4 November 1st 05 09:06 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 09:56 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 12:25 AM


All times are GMT +1. The time now is 12:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"