Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default find text match, then grab text following

I want to find a text portion match in a cell. If there is a match, I want
to extract the text that follows. For example,
If there is the following text in a cell:
abc def (ghi) jkl

I search for "def", then I want to extract the text "ghi" and copy this to
another cell.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default find text match, then grab text following

look at the post titled "string matching" from 6-5 and see if any of the replies
may help

--


Gary


"pcd81" wrote in message
...
I want to find a text portion match in a cell. If there is a match, I want
to extract the text that follows. For example,
If there is the following text in a cell:
abc def (ghi) jkl

I search for "def", then I want to extract the text "ghi" and copy this to
another cell.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default find text match, then grab text following

On Fri, 8 Jun 2007 12:09:00 -0700, pcd81
wrote:

I want to find a text portion match in a cell. If there is a match, I want
to extract the text that follows. For example,
If there is the following text in a cell:
abc def (ghi) jkl

I search for "def", then I want to extract the text "ghi" and copy this to
another cell.


When you write "extract the text that follows", what exactly do you mean?

In your example, you reference "ghi" but the characters that follow "def" are
(ghi) jkl

So you are not extracting the parentheses, nor the "jkl".

The following UDF will return "ghi" from your string "abc def (ghi) jkl"

You may need to be more explicit in your requirements, if this does not do what
you want. Basically, it returns the "word" that follows your string. A word
is defined as a series of characters in the class [A-Za-z0-9_]

So "ghi" would also be extracted from the string: "abc defghi jkl"

================================================
Option Explicit

Function NextWord(str As String, TextToFind As String) As String
Dim oRegex As Object
Dim mcMatchCollection As Object
Dim sPattern As String

sPattern = TextToFind & ".*?(\w+)"

Set oRegex = CreateObject("VBScript.RegExp")
With oRegex
.Global = True
.IgnoreCase = True
.Pattern = sPattern
End With

If oRegex.Test(str) = True Then
Set mcMatchCollection = oRegex.Execute(str)
NextWord = mcMatchCollection(0).SubMatches(0)
End If

End Function
=================================================

--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
vlookup to find match only part of a text value David Excel Discussion (Misc queries) 4 August 29th 08 02:35 PM
grab cell text from multi-tab workbook, show text in another workb pfa Excel Worksheet Functions 16 August 10th 07 08:50 PM
How do I grab the date from a text string? [email protected] Excel Worksheet Functions 4 June 6th 06 07:55 AM
Sum values in multiple sheets using Lookup to find a text match CheriT63 Excel Worksheet Functions 7 December 4th 05 02:33 AM
Find text in another workbook and paste if found match - VBA Pasmatos Excel Discussion (Misc queries) 1 November 10th 05 01:00 PM


All times are GMT +1. The time now is 02:10 PM.

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

About Us

"It's about Microsoft Excel"