LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Extract digits

Hi Robert,

Am Wed, 20 Nov 2019 10:48:20 -0800 (PST) schrieb RG III:

I have a set of strings that contain digits at the right end, such as:

s1 = "abcd1234"
s2 = "g10"
s3 = "yyy19123"

The data will always contain alpha chars on the left, and digits on the right.


try:

For i = 1 To Len(s2)
If Asc(Mid(s2, i, 1)) 47 And Asc(Mid(s2, i, 1)) < 58 Then
myNumber = CInt(Mid(s2, i))
Exit Sub
End If
Next

or:

Sub Test2()
Dim re As Object, Match As Object
Dim ptrn As String

s1 = "abcd1234"
s2 = "g10"
s3 = "yyy19123"

ptrn = "[\d]{1,}"
Set re = CreateObject("vbscript.Regexp")
re.pattern = ptrn
re.IgnoreCase = False
re.Global = True
Set Match = re.Execute(s3)
MsgBox Match(0).Value
End Sub


Regards
Claus B.
--
Windows10
Office 2016
 
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
how do I extract the last three digits from each cell in column? PeggyT Excel Discussion (Misc queries) 5 April 4th 23 11:22 AM
To extract the number if there is niumeric in right most digits pol Excel Discussion (Misc queries) 4 October 16th 08 07:21 AM
how to extract digits from a row of numbers preydd Excel Worksheet Functions 2 September 3rd 08 04:32 PM
I need to extract the first 3 digits from a cell (ex: AAG12345)? Rob Excel Worksheet Functions 6 April 21st 07 11:45 PM
Extract Digits Questions [email protected] Excel Programming 5 December 27th 05 10:34 PM


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