VBA find character and extract number

neveu

Board Regular
Joined
Jan 27, 2009
Messages
225
Hello,

I have a list of items in column E that contains information like these

Excel Workbook
X
410T2N30
510T3N30
614T2N30
714TN
815T2N30
920TN
1021T2N30
1121T2N60
1221T3N30
132FM20TN
1430T0,5N60
1530T0.5N3FM
1630T2.5%N31
1730TN
1840TN
1945T2N60
2045T3N60
2145TN
2260T1
2360T1N75
2460TN
2575TN
268T2N30
2790TN
28BEZ10T3N30
29BEZ3T3.5N3
30BEZN
31Sofort
32Sofort2%
33Sofort3%
Open Invoices
Excel 2007



What i would need to do is the folowing,
if the first 3 characters are BEZ than to search for the character "T" in the string and to retrieve the number after it in the corespondign cell on column M. otherwise to put "N"
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
if the first 3 characters are BEZ than to search for the character "T" in the string and to retrieve the number after it in the corespondign cell on column M. otherwise to put "N"

To retrive the number after the character "T" try in cell F2

=IF(TRIM(LEFT(E3,3))="BEZ",MID(E3,FIND("T",E3)+1,10),"N")

i didnt get "corespondign cell on column M", what does Column M contain
is it if string contain "BEZ" then vlookup number after T from another column
 
Upvote 0
hello Maresh,


thank you very much for your help.
how could i translate this into VBA code?
i would need it to insert in a bigger procedure.

could you please help?

thank you
 
Upvote 0
just checked it and for text BEZ10T3N30 it returns 3N30 but i would only need 3.
and for BEZ3T3.5N3 it returns 3.5N3 but i only need 3.5

...:(
 
Upvote 0
neveu,

try this:

Code:
Function MatchNum(Str As String) As String
With CreateObject("VBScript.RegExp")
     .Pattern = "(((-|\+)?\d+\.?\d*)|any)"
     MatchNum = .Execute(Str)(0)
End With

End Function

Sub test35345435()
Dim myRange As Range, c As Range

Set myRange = Sheet1.Range("B2:B31")

For Each c In myRange
    If Left(c.Value, 3) = "BEZ" Then
        On Error Resume Next
        Sheet1.Range("M" & c.Row).Value = _
            MatchNum(Mid(c.Value, InStr(1, c.Value, "T", vbTextCompare), 255))
    End If
Next c
End Sub

I assumed that your worksheet code name is sheet1 and your range is B2:B31, change it if needed.
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top