LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Dave Peterson
 
Posts: n/a
Default

I'm not Dana, but you could use it an adjacent cell as another worksheet
function:

=LastGroupOfNumbers(a1)

And drag down the column, well, if your data is in a column.

And you could actually update the values in place (overwriting the original
values) if you wanted via a macro.

Sub testme()
Dim myCell As Range
Dim myRng As Range
Set myRng = Selection
For Each myCell In myRng.Cells
With myCell
.Value = LastGroupOfNumbers(.Value)
End With
Next myCell
End Sub

It kind of depends on what you meant...



Biff wrote:

Hi Dana!

How could this be used on a range and without the array elements being
predefined?

Biff

"Dana DeLouis" wrote in message
...
Hi. Here's just one way...

Option Explicit
Public RE As RegExp

Function LastGroupOfNumbers(s)
'// Microsoft VBScript Regular Expressions 5.5

Dim Matches As MatchCollection
Const k As String = "(\d+)\D*$"

If RE Is Nothing Then Set RE = New RegExp
With RE
.IgnoreCase = True
.Global = True
.Pattern = k

If .Test(s) Then
Set Matches = .Execute(s)
LastGroupOfNumbers = Matches(0).SubMatches(0)
End If
End With
End Function

Sub TestIt()
Dim v, j
v = Array("W2424", "W2424P", "W3D2412", "W1836PLR", "DW362424L",
"W3D1560DTL")
For j = LBound(v) To UBound(v)
Debug.Print v(j); " - "; LastGroupOfNumbers(v(j))
Next j
End Sub

Returns:
W2424 - 2424
W2424P - 2424
W3D2412 - 2412
W1836PLR - 1836
DW362424L - 362424
W3D1560DTL - 1560

HTH
--
Dana DeLouis
Win XP & Office 2003


"Mr. Me" wrote in message
om...
I have Excel 2000. I would like to get a Regexp function. I have model
numbers that I want to sort. Model numbers are composed of a prefix
(variable
length), the model number (2-6 digits), and a suffix (variable length).
The
left, right and mid functions only work if the prefix is a fixed length,
thus
I need regexp to pick out the first group of 2-6 digits in a row, then
sort
on that.

SO if I had a function that would look at column A (with the whole model
#)
and put the modified, sortable model number in col B, that would be
great.

Example model #s and extracted sort key:
W2424 2424
W2424P 2424
W3D2412 2412
W1836PLR 1836
DW362424L 362424
W3D1560DTL 1560

Thanks!

--
Sig: Say no to fixed width HTML tables. They look terrible in most
browsers.




--

Dave Peterson
 
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
Setting tab colours on Excel spreadsheets (for Excel 2000) S Excel Discussion (Misc queries) 2 June 15th 05 03:42 PM
Excel 2000 to Excel 97 frankie Excel Discussion (Misc queries) 2 June 14th 05 12:33 AM
can you tell me the difference between excel 2000 and excel 2003 mregel Excel Discussion (Misc queries) 2 June 13th 05 02:19 PM
Excel XP 2002 Vs. Excel 2000 Samantha Excel Discussion (Misc queries) 0 April 18th 05 03:54 PM
How do I update Excel 2000 macros to work in Excel 2002? BobPetrich Excel Discussion (Misc queries) 3 January 4th 05 04:06 PM


All times are GMT +1. The time now is 09:57 AM.

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"