J
Johnny Bravo
I just wanted to thank you for this VB code.
It's just what i needed.
P.S. sorry for my poor english
www.exciter.gr wrote:
You can try this Custom Function.
26-Oct-07
You can try this Custom Function. Copy the code into the VBA window o
your file and then go to cell B1 and type =RemoveTexts(A1
This function checks each character of your target cell and keeps onl
numeric characters. Before returning the number, it actually convert
it to numeric (so 123 will be number, not text). For empty or text
only cells, it will return zero
Public Function RemoveTexts(Target As Range
Dim t As Strin
For i = 1 To Len(Target.Value
t = Mid(Target.Value, i, 1
If IsNumeric(t) = True The
RemoveTexts = RemoveTexts &
End I
Next
RemoveTexts = Val(RemoveTexts
End Functio
Previous Posts In This Thread:
Remove Numbers from Alphanumeric String
Hi
I have a value in Cell A of ABC123
I want Cell B1 to contain the 123 from this cell
Can anyone tell me the formula to enter in B1. I'm sure I've seen it
somewhere before but can't put my finger on it
Thanks
Dave
if it's always the 4th position, then =mid(A1,4,255).
if it's always the 4th position, then =mid(A1,4,255). If you want it to be
numeric, then =1*mid(a1,4,255)
If the position is unknown but is always letters followed by numbers,
ctrl+shift+enter this
=1*MID(A1,MATCH(FALSE,ISERROR(1*MID(A1,ROW($1:$20),1)),0),255
Bob Umla
Excel MV
RE: Remove Numbers from Alphanumeric String
Hi
Try this
=RIGHT(A1,3
Thanks
-
Farhad Hodja
:
RE: Remove Numbers from Alphanumeric String
Try this UDF
Function letteronly(r As Range) As Strin
letteronly = "
If Application.WorksheetFunction.IsText(r.Value) The
s = r.Valu
For i = 49 To 5
s = Replace(s, Chr(i), ""
Next
letteronly =
End I
End Functio
--
Gary''s Student - gsnu20075
:
You can try this Custom Function.
You can try this Custom Function. Copy the code into the VBA window o
your file and then go to cell B1 and type =RemoveTexts(A1
This function checks each character of your target cell and keeps onl
numeric characters. Before returning the number, it actually convert
it to numeric (so 123 will be number, not text). For empty or text
only cells, it will return zero
Public Function RemoveTexts(Target As Range
Dim t As Strin
For i = 1 To Len(Target.Value
t = Mid(Target.Value, i, 1
If IsNumeric(t) = True The
RemoveTexts = RemoveTexts &
End I
Next
RemoveTexts = Val(RemoveTexts
End Functio
Thanks Farhad. This works, but my string does not always have 3 digits.
Thanks Farhad. This works, but my string does not always have 3 digits. Som
are 4 or 5 digits
:
Re: Remove Numbers from Alphanumeric String
This returns #N/
:
Hi GarysStudent. Can you explain how to use this?
Hi GarysStudent. Can you explain how to use this? Thanks
:
Re: Remove Numbers from Alphanumeric String
This does not seem to work
:
Probably because you *didn't* enter it the proper way.It's an *array* formula!
Probably because you *didn't* enter it the proper way
It's an *array* formula
--
Array formulas must be entered with CSE, <Ctrl> <Shift > <Enter>, instead o
the regular <Enter>, which will *automatically* enclose the formula in curly
brackets, which *cannot* be done manually.
You *must also* use CSE when revising the formula.
You can click in the cell containing the formula.
Then click in the formula bar, hold down
<Ctrl> and <Shift>
Then hit <Enter>
--
HTH,
RD
---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
be
Re: Remove Numbers from Alphanumeric String
Try...
=REPLACE(A1,1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))-1,"")
Note that the formula will return the number as a text value. To
return the number as a numerical value, add +0 at the end of the
formula.
Hope this helps!
Works for me.Where did you store the code?
Works for me.
Where did you store the code?
Copy and paste into a general module in your workbook.
Alt + F11 to go to Visual Basic Editor.
CTRL + r to open Project Explorer window.
Select your workbook/project and right-click>insert>module.
Paste the UDF into that module.
Alt + q to return to Excel sheet.
Enter the formula as shown.
Gord Dibben MS Excel MVP
[/url] Custom Excel Applications! wrote:
Davejust tried my solution again and it works fine.
Dave
just tried my solution again and it works fine.
Please follow the procedure step by step to make it work for you too:
1. Open your excel file (suppose its name is yourfile.xls)
2. Go to Tools/Macro/Visual Basic Editor
3. Right click on the line VBAProject(yourfile.xls) on the left list
and click on Insert Module
4. Paste the code into the white window on the right:
Public Function RemoveTexts(Target As Range)
Dim t As String
For i = 1 To Len(Target.Value)
t = Mid(Target.Value, i, 1)
If IsNumeric(t) = True Then
RemoveTexts = RemoveTexts & t
End If
Next i
RemoveTexts = Val(RemoveTexts)
End Function
5. Go back to your excel sheet, type ABC123 or anything else in Cell
A1
6. Type the formula: "=RemoveTexts(A1)" without the quotes into Cell
B1 and press enter
7. It should return the correct result
Good luck!
Re: Remove Numbers from Alphanumeric String
Assuming the digits are all contiguous:
B1:
=LOOKUP(9.99E+307,--MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},
A1&"0123456789")),ROW(INDIRECT("1:"&LEN(A1)))))
If the digits are not contiguous, you can use this UDF:
=======================
Option Explicit
Function Digits(str As String)
Dim re As Object
Const sPat As String = "\D"
Const sRes As String = ""
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = sPat
Digits = re.Replace(str, sRes)
If IsNumeric(Digits) Then Digits = CDbl(Digits)
End Function
===========================
To enter the UDF, <alt-F11> opens the VBEditor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Module and paste the
code above into the window that opens.
You can then use the formula =Digits(cell_ref) in any cell. e.g.
B1: =Digits(A1)
--ron
Re: Remove Numbers from Alphanumeric String
Please note that the formulas I supplied return the digits as a value, and not
as a string. What this means is that leading 0's will get dropped.
If you require that the digits be returned as a string, then merely omit the
next to last line in the UDF (The line that starts with " If IsNumeric..."
--ron
Many thanks for this reply!
Many thanks for this reply! It does now work. This solution would be very
useful for anyone trying to achieve a similar result!!
Cheers again
Dave
:
This formula does work when enterred as you mentioned.
This formula does work when enterred as you mentioned. Can you please provide
some info on what this CSE method is and why it is used. It is new to me.
Thanks!
Dave
:
Re: Remove Numbers from Alphanumeric String
You can start here:
http://www.cpearson.com/excel/ArrayFormulas.aspx
--
HTH,
RD
---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
Is there a way to do something similar with IsText so that ABC is left, and
Is there a way to do something similar with IsText so that ABC is left, and
123 is removed?
Thanks!
Dave
:
Re: Remove Numbers from Alphanumeric String
You could use this UDF, which will return either Text or Digits depending on
the setting of the second (optional) argument:
==========================
Option Explicit
Function TextOrDigits(str As String, Optional Txt As Boolean = True)
Dim re As Object
Dim sPat As String
Const sRes As String = ""
If Txt = True Then
sPat = "\d"
Else
sPat = "\D"
End If
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = sPat
TextOrDigits = re.Replace(str, sRes)
End Function
=================================
So to return just Text:
=TextOrDigits(A1)
or
=TextOrDigits(A1,True)
and to return just digits:
=TextOrDigits(A1,False)
--ron
Submitted via EggHeadCafe - Software Developer Portal of Choice
Custom Favorites Web Site with MongoDb and NoRM
http://www.eggheadcafe.com/tutorial...favorites-web-site-with-mongodb-and-norm.aspx
It's just what i needed.
P.S. sorry for my poor english
www.exciter.gr wrote:
You can try this Custom Function.
26-Oct-07
You can try this Custom Function. Copy the code into the VBA window o
your file and then go to cell B1 and type =RemoveTexts(A1
This function checks each character of your target cell and keeps onl
numeric characters. Before returning the number, it actually convert
it to numeric (so 123 will be number, not text). For empty or text
only cells, it will return zero
Public Function RemoveTexts(Target As Range
Dim t As Strin
For i = 1 To Len(Target.Value
t = Mid(Target.Value, i, 1
If IsNumeric(t) = True The
RemoveTexts = RemoveTexts &
End I
Next
RemoveTexts = Val(RemoveTexts
End Functio
Previous Posts In This Thread:
Remove Numbers from Alphanumeric String
Hi
I have a value in Cell A of ABC123
I want Cell B1 to contain the 123 from this cell
Can anyone tell me the formula to enter in B1. I'm sure I've seen it
somewhere before but can't put my finger on it
Thanks
Dave
if it's always the 4th position, then =mid(A1,4,255).
if it's always the 4th position, then =mid(A1,4,255). If you want it to be
numeric, then =1*mid(a1,4,255)
If the position is unknown but is always letters followed by numbers,
ctrl+shift+enter this
=1*MID(A1,MATCH(FALSE,ISERROR(1*MID(A1,ROW($1:$20),1)),0),255
Bob Umla
Excel MV
RE: Remove Numbers from Alphanumeric String
Hi
Try this
=RIGHT(A1,3
Thanks
-
Farhad Hodja
:
RE: Remove Numbers from Alphanumeric String
Try this UDF
Function letteronly(r As Range) As Strin
letteronly = "
If Application.WorksheetFunction.IsText(r.Value) The
s = r.Valu
For i = 49 To 5
s = Replace(s, Chr(i), ""
Next
letteronly =
End I
End Functio
--
Gary''s Student - gsnu20075
:
You can try this Custom Function.
You can try this Custom Function. Copy the code into the VBA window o
your file and then go to cell B1 and type =RemoveTexts(A1
This function checks each character of your target cell and keeps onl
numeric characters. Before returning the number, it actually convert
it to numeric (so 123 will be number, not text). For empty or text
only cells, it will return zero
Public Function RemoveTexts(Target As Range
Dim t As Strin
For i = 1 To Len(Target.Value
t = Mid(Target.Value, i, 1
If IsNumeric(t) = True The
RemoveTexts = RemoveTexts &
End I
Next
RemoveTexts = Val(RemoveTexts
End Functio
Thanks Farhad. This works, but my string does not always have 3 digits.
Thanks Farhad. This works, but my string does not always have 3 digits. Som
are 4 or 5 digits
:
Re: Remove Numbers from Alphanumeric String
This returns #N/
:
Hi GarysStudent. Can you explain how to use this?
Hi GarysStudent. Can you explain how to use this? Thanks
:
Re: Remove Numbers from Alphanumeric String
This does not seem to work
:
Probably because you *didn't* enter it the proper way.It's an *array* formula!
Probably because you *didn't* enter it the proper way
It's an *array* formula
--
Array formulas must be entered with CSE, <Ctrl> <Shift > <Enter>, instead o
the regular <Enter>, which will *automatically* enclose the formula in curly
brackets, which *cannot* be done manually.
You *must also* use CSE when revising the formula.
You can click in the cell containing the formula.
Then click in the formula bar, hold down
<Ctrl> and <Shift>
Then hit <Enter>
--
HTH,
RD
---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
be
Re: Remove Numbers from Alphanumeric String
Try...
=REPLACE(A1,1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))-1,"")
Note that the formula will return the number as a text value. To
return the number as a numerical value, add +0 at the end of the
formula.
Hope this helps!
Works for me.Where did you store the code?
Works for me.
Where did you store the code?
Copy and paste into a general module in your workbook.
Alt + F11 to go to Visual Basic Editor.
CTRL + r to open Project Explorer window.
Select your workbook/project and right-click>insert>module.
Paste the UDF into that module.
Alt + q to return to Excel sheet.
Enter the formula as shown.
Gord Dibben MS Excel MVP
[/url] Custom Excel Applications! wrote:
Davejust tried my solution again and it works fine.
Dave
just tried my solution again and it works fine.
Please follow the procedure step by step to make it work for you too:
1. Open your excel file (suppose its name is yourfile.xls)
2. Go to Tools/Macro/Visual Basic Editor
3. Right click on the line VBAProject(yourfile.xls) on the left list
and click on Insert Module
4. Paste the code into the white window on the right:
Public Function RemoveTexts(Target As Range)
Dim t As String
For i = 1 To Len(Target.Value)
t = Mid(Target.Value, i, 1)
If IsNumeric(t) = True Then
RemoveTexts = RemoveTexts & t
End If
Next i
RemoveTexts = Val(RemoveTexts)
End Function
5. Go back to your excel sheet, type ABC123 or anything else in Cell
A1
6. Type the formula: "=RemoveTexts(A1)" without the quotes into Cell
B1 and press enter
7. It should return the correct result
Good luck!
Re: Remove Numbers from Alphanumeric String
Assuming the digits are all contiguous:
B1:
=LOOKUP(9.99E+307,--MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},
A1&"0123456789")),ROW(INDIRECT("1:"&LEN(A1)))))
If the digits are not contiguous, you can use this UDF:
=======================
Option Explicit
Function Digits(str As String)
Dim re As Object
Const sPat As String = "\D"
Const sRes As String = ""
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = sPat
Digits = re.Replace(str, sRes)
If IsNumeric(Digits) Then Digits = CDbl(Digits)
End Function
===========================
To enter the UDF, <alt-F11> opens the VBEditor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Module and paste the
code above into the window that opens.
You can then use the formula =Digits(cell_ref) in any cell. e.g.
B1: =Digits(A1)
--ron
Re: Remove Numbers from Alphanumeric String
Please note that the formulas I supplied return the digits as a value, and not
as a string. What this means is that leading 0's will get dropped.
If you require that the digits be returned as a string, then merely omit the
next to last line in the UDF (The line that starts with " If IsNumeric..."
--ron
Many thanks for this reply!
Many thanks for this reply! It does now work. This solution would be very
useful for anyone trying to achieve a similar result!!
Cheers again
Dave
:
This formula does work when enterred as you mentioned.
This formula does work when enterred as you mentioned. Can you please provide
some info on what this CSE method is and why it is used. It is new to me.
Thanks!
Dave
:
Re: Remove Numbers from Alphanumeric String
You can start here:
http://www.cpearson.com/excel/ArrayFormulas.aspx
--
HTH,
RD
---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
Is there a way to do something similar with IsText so that ABC is left, and
Is there a way to do something similar with IsText so that ABC is left, and
123 is removed?
Thanks!
Dave
:
Re: Remove Numbers from Alphanumeric String
You could use this UDF, which will return either Text or Digits depending on
the setting of the second (optional) argument:
==========================
Option Explicit
Function TextOrDigits(str As String, Optional Txt As Boolean = True)
Dim re As Object
Dim sPat As String
Const sRes As String = ""
If Txt = True Then
sPat = "\d"
Else
sPat = "\D"
End If
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = sPat
TextOrDigits = re.Replace(str, sRes)
End Function
=================================
So to return just Text:
=TextOrDigits(A1)
or
=TextOrDigits(A1,True)
and to return just digits:
=TextOrDigits(A1,False)
--ron
Submitted via EggHeadCafe - Software Developer Portal of Choice
Custom Favorites Web Site with MongoDb and NoRM
http://www.eggheadcafe.com/tutorial...favorites-web-site-with-mongodb-and-norm.aspx