LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default Copy string of characters

On Tue, 26 Aug 2008 07:01:00 -0700, BRB wrote:

Have a variation to a previous question:
Need to copy a string of characters from one cell to another. Here is what
the cell looks like:

Cells:
A1 = Some text, HW012345, more text, HW034567, more text
A2 = Some text
A3 = Some text, HW056783, more text, HW035791, more text

In column B I need the following result:
B1 = HW012345 HW034567
B2 = (blank)
B3 = HW056783 HW035791

Thanks for any help




The following will return a space-separated string of all of the substrings in
your original string that start with HW0 and are followed by a sequence of
digits.

If this is not exactly what you want, it can be easily modified.

To enter this User Defined Function, <alt-F11 opens the VB Editor. Ensure
your project is highlighted in the Project Explorer window, then Insert/Module
and paste the code below into the window that opens.

To use this, enter =ReExtr(cell_ref) into some cell containing the string to be
tested.

================================
Option Explicit
Function ReExtr(str As String) As String
Dim sArr() As String
Dim i As Long
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "\bHW0\d+\b"
If re.test(str) = True Then
Set mc = re.Execute(str)
ReDim sArr(mc.Count - 1)
For i = 0 To mc.Count - 1
sArr(i) = mc(i)
Next i
ReExtr = Join(sArr, " ")
End If
End Function
=========================================
--ron


 
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
Count characters within a string Francisco Excel Worksheet Functions 4 April 10th 07 05:28 PM
Separate characters in a string viadisky Excel Discussion (Misc queries) 2 February 1st 06 05:35 PM
summing characters in a string DMG Excel Worksheet Functions 4 December 20th 05 02:44 PM
select a string of characters Did Excel Worksheet Functions 7 August 17th 05 04:24 AM
pulling characters out of a string Patrick Excel Worksheet Functions 3 November 12th 04 06:58 PM


All times are GMT +1. The time now is 03:20 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"