Need Function for Text To Columns

J

JW

I have some data that I want to extract a number from. Here is an
example.

ABSD (P+3.9%)

I want to get at the 3.9, and I'm assuming I would want to use the "+"
sign and the "%" sign as delimiters somehow. Is there a function that
would help me do this all in one step?

I can get there using text to columns, but that is very manual and
requires several steps.

I'm out of ideas!!

Thanks.
 
G

Gord Dibben

Are you up for a quick macro?

Sub RemoveAlphas()
' Remove alpha characters from a string.
' except for decimal points
Dim intI As Integer
Dim rngR As Range, rngRR As Range
Dim strNotNum As String, strTemp As String
Set rngRR = Selection.SpecialCells(xlCellTypeConstants, _
xlTextValues)
For Each rngR In rngRR
strTemp = ""
For intI = 1 To Len(rngR.Value)
If Mid(rngR.Value, intI, 1) Like "[0-9.]" Then
strNotNum = Mid(rngR.Value, intI, 1)
Else: strNotNum = ""
End If
strTemp = strTemp & strNotNum
Next intI
rngR.Value = strTemp
Next rngR
End Sub


Gord Dibben MS Excel MVP
 
G

Gord Dibben

JW

Ignore my post.

I replied based on your example of ABSD (P+3.9%)

Won't work with your second posting examples.


Gord Dibben MS Excel MVP
 
S

Sasa Stankovic

THIS WORKS PERFECTLY:
Assume that your data is in cell A1, enter fomula in cell b1 and enjoy:
=MID(A1;FIND("+";A1)+1;FIND("%";A1)-FIND("+";A1))

greetings
 
S

Sasa Stankovic

dont you thing my formula is a little bit easier for non developers?
but, you are quick... this vba in little time... :)
Gord Dibben said:
Are you up for a quick macro?

Sub RemoveAlphas()
' Remove alpha characters from a string.
' except for decimal points
Dim intI As Integer
Dim rngR As Range, rngRR As Range
Dim strNotNum As String, strTemp As String
Set rngRR = Selection.SpecialCells(xlCellTypeConstants, _
xlTextValues)
For Each rngR In rngRR
strTemp = ""
For intI = 1 To Len(rngR.Value)
If Mid(rngR.Value, intI, 1) Like "[0-9.]" Then
strNotNum = Mid(rngR.Value, intI, 1)
Else: strNotNum = ""
End If
strTemp = strTemp & strNotNum
Next intI
rngR.Value = strTemp
Next rngR
End Sub


Gord Dibben MS Excel MVP

I have some data that I want to extract a number from. Here is an
example.

ABSD (P+3.9%)

I want to get at the 3.9, and I'm assuming I would want to use the "+"
sign and the "%" sign as delimiters somehow. Is there a function that
would help me do this all in one step?

I can get there using text to columns, but that is very manual and
requires several steps.

I'm out of ideas!!

Thanks.
 
S

Sasa Stankovic

I'm using ";" as list separator - you should use ";" or "," depending on
your regional settings
Sasa Stankovic said:
THIS WORKS PERFECTLY:
Assume that your data is in cell A1, enter fomula in cell b1 and enjoy:
=MID(A1;FIND("+";A1)+1;FIND("%";A1)-FIND("+";A1))

greetings
 
Top