#1   Report Post  
Posted to microsoft.public.excel.misc
MBD MBD is offline
external usenet poster
 
Posts: 1
Default removing alpha

I have a cells that have numbers and alphas...for example, 1A, 1B, 1C.....in
order to join this table to a corresponding table in GIS, I need to remove
the alpha leaving me with 1,2,3....any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.misc
CLR CLR is offline
external usenet poster
 
Posts: 594
Default removing alpha

ASAP Utilities, a free Add-in available at www.asap-utilities.com has a
feature that will do it nicely.........

Vaya con Dios,
Chuck, CABGx3


"MBD" wrote in message
...
I have a cells that have numbers and alphas...for example, 1A, 1B,

1C.....in
order to join this table to a corresponding table in GIS, I need to remove
the alpha leaving me with 1,2,3....any ideas?



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default removing alpha

If all the values are one number and one character as in your examples, then
use the formula:

=LEFT(A1,1)
--
Gary''s Student - gsnu200727


"MBD" wrote:

I have a cells that have numbers and alphas...for example, 1A, 1B, 1C.....in
order to join this table to a corresponding table in GIS, I need to remove
the alpha leaving me with 1,2,3....any ideas?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 118
Default removing alpha

OR
if you have one number and 2 letters
Use imagination for other options.

=IF(LEN(A1=2),LEFT(A1,1),LEFT(A1,2))

HTH
Michael M

"Gary''s Student" wrote:

If all the values are one number and one character as in your examples, then
use the formula:

=LEFT(A1,1)
--
Gary''s Student - gsnu200727


"MBD" wrote:

I have a cells that have numbers and alphas...for example, 1A, 1B, 1C.....in
order to join this table to a corresponding table in GIS, I need to remove
the alpha leaving me with 1,2,3....any ideas?

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,202
Default removing alpha

I have a cells that have numbers and alphas...for example, 1A, 1B,
1C.....in
order to join this table to a corresponding table in GIS, I need to remove
the alpha leaving me with 1,2,3....any ideas?


If the number part of your cell contents are either whole numbers or, if a
floating point number, uses a dot as the decimal point AND if the cell
contents **always** has the number part before the alpha part, then create a
macro with this code in it...

Dim S
For Each S In Selection
If Len(S) 0 Then S.Cells.Value = Val(S.Cells.Value)
Next

....then select the range you want to operate over and, finally, apply this
macro to it.

Rick



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default removing alpha

On Sun, 3 Jun 2007 15:27:00 -0700, MBD wrote:

I have a cells that have numbers and alphas...for example, 1A, 1B, 1C.....in
order to join this table to a corresponding table in GIS, I need to remove
the alpha leaving me with 1,2,3....any ideas?


If the numbers are all together (e.g. 1AB 123AB AB1234AB) , then you can use
this function:

=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 numbers and letters are randomly distributed (e.g. ab123cd456ef78) and
you want to remove all the non-numbers, then this UDF:

--------------------------------------
Option Explicit
Function RemAlpha(str As String)
Dim oRegExp As Object
Set oRegExp = CreateObject("VBScript.RegExp")

With oRegExp
.IgnoreCase = True
.Global = True
oRegExp.Pattern = "\D"

RemAlpha = oRegExp.Replace(str, "")
End With
End Function
--------------------------------------

To enter the UDF, <alt-F11 opens the VB Editor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Modula and paste the
code above into the window that opens.

In some cell, enter the formula:

=RemAlpha(cell_ref)

and it will return only the digits.
--ron
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default removing alpha

On Sun, 3 Jun 2007 15:27:00 -0700, MBD wrote:

I have a cells that have numbers and alphas...for example, 1A, 1B, 1C.....in
order to join this table to a corresponding table in GIS, I need to remove
the alpha leaving me with 1,2,3....any ideas?


Slightly Simpler:

====================
Option Explicit
Function RemAlpha(str As String)
Dim oRegExp As Object
Set oRegExp = CreateObject("VBScript.RegExp")

With oRegExp
.IgnoreCase = True
.Global = True
.Pattern = "\D"

RemAlpha = oRegExp.Replace(str, "")
End With
End Function
===========================
--ron
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default removing alpha

Ron

May I suggest a small change?

RemAlpha = oRegExp.Replace(str, "") * 1

Turns the numbers back into numbers.


Gord

On Sun, 03 Jun 2007 21:22:58 -0400, Ron Rosenfeld
wrote:

On Sun, 3 Jun 2007 15:27:00 -0700, MBD wrote:

I have a cells that have numbers and alphas...for example, 1A, 1B, 1C.....in
order to join this table to a corresponding table in GIS, I need to remove
the alpha leaving me with 1,2,3....any ideas?


Slightly Simpler:

====================
Option Explicit
Function RemAlpha(str As String)
Dim oRegExp As Object
Set oRegExp = CreateObject("VBScript.RegExp")

With oRegExp
.IgnoreCase = True
.Global = True
.Pattern = "\D"

RemAlpha = oRegExp.Replace(str, "")
End With
End Function
===========================
--ron


  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default removing alpha

On Sun, 03 Jun 2007 18:43:23 -0700, Gord Dibben <gorddibbATshawDOTca wrote:

Ron

May I suggest a small change?

RemAlpha = oRegExp.Replace(str, "") * 1

Turns the numbers back into numbers.


Gord


Good catch. I omitted the string to number conversion inadvertently.

Although in the version I generally use, I do it this way:

Function RemAlpha(str As String) As Long

since I'm only doing integers. If I were doing decimal numbers, the "pattern"
would be different, and the function call would be:

Function RemAlpha(str As String) As Double

I think that putting it into the Function call makes it more clear as to what
is being returned.
--ron
  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default removing alpha

Thanks Ron

I just keep learning.


Gord

On Sun, 03 Jun 2007 22:21:01 -0400, Ron Rosenfeld
wrote:

On Sun, 03 Jun 2007 18:43:23 -0700, Gord Dibben <gorddibbATshawDOTca wrote:

Ron

May I suggest a small change?

RemAlpha = oRegExp.Replace(str, "") * 1

Turns the numbers back into numbers.


Gord


Good catch. I omitted the string to number conversion inadvertently.

Although in the version I generally use, I do it this way:

Function RemAlpha(str As String) As Long

since I'm only doing integers. If I were doing decimal numbers, the "pattern"
would be different, and the function call would be:

Function RemAlpha(str As String) As Double

I think that putting it into the Function call makes it more clear as to what
is being returned.
--ron




  #11   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default removing alpha

On Mon, 04 Jun 2007 11:38:13 -0700, Gord Dibben <gorddibbATshawDOTca wrote:

Thanks Ron

I just keep learning.


Gord



Me too!
--ron
  #12   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,202
Default removing alpha

I have a cells that have numbers and alphas...for example, 1A, 1B,
1C.....in
order to join this table to a corresponding table in GIS, I need to remove
the alpha leaving me with 1,2,3....any ideas?


Slightly Simpler:

====================
Option Explicit
Function RemAlpha(str As String)
Dim oRegExp As Object
Set oRegExp = CreateObject("VBScript.RegExp")

With oRegExp
.IgnoreCase = True
.Global = True
.Pattern = "\D"

RemAlpha = oRegExp.Replace(str, "")
End With
End Function
===========================


I would think the String values would be short enough that this macro would
work fairly quickly too...

Function RemAlpha(ByVal str As String) As String
Dim X As Long
For X = 1 To Len(str)
If Mid$(str, X, 1) Like "[!0-9]" Then Mid$(str, X) = " "
Next
RemAlpha = Replace(str, " ", "")
End Function

And if we wanted to return a number instead of a string value, this macro
instead...

Function RemAlpha(ByVal str As String) As Long
Dim X As Long
For X = 1 To Len(str)
If Mid$(str, X, 1) Like "[!0-9]" Then Mid$(str, X) = " "
Next
RemAlpha = CLng(Replace(str, " ", ""))
End Function

Rick

  #13   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default removing alpha

On Sun, 3 Jun 2007 22:18:00 -0400, "Rick Rothstein \(MVP - VB\)"
wrote:

I would think the String values would be short enough that this macro would
work fairly quickly too...

Function RemAlpha(ByVal str As String) As String
Dim X As Long
For X = 1 To Len(str)
If Mid$(str, X, 1) Like "[!0-9]" Then Mid$(str, X) = " "
Next
RemAlpha = Replace(str, " ", "")
End Function

And if we wanted to return a number instead of a string value, this macro
instead...

Function RemAlpha(ByVal str As String) As Long
Dim X As Long
For X = 1 To Len(str)
If Mid$(str, X, 1) Like "[!0-9]" Then Mid$(str, X) = " "
Next
RemAlpha = CLng(Replace(str, " ", ""))
End Function

Rick


I find that frequently the variability in the data is not expressed in the
initial posting.

If we accept the premise, from his example, that the digits always come first,
and also that he wants a NUMBER returned, we could shorten the UDF even
further:

Function RemAlpha(str)
RemAlpha = Val(str)
End Function



--ron
  #14   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default removing alpha

On Mon, 04 Jun 2007 00:58:48 -0400, Ron Rosenfeld
wrote:

I find that frequently the variability in the data is not expressed in the
initial posting.

If we accept the premise, from his example, that the digits always come first,
and also that he wants a NUMBER returned, we could shorten the UDF even
further:

Function RemAlpha(str)
RemAlpha = Val(str)
End Function


Hmmm -- I now see you used that same method in your initial post.


--ron
  #15   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,202
Default removing alpha

If we accept the premise, from his example, that the digits always come
first,
and also that he wants a NUMBER returned, we could shorten the UDF even
further:

Function RemAlpha(str)
RemAlpha = Val(str)
End Function


Yes, I addressed that assumption and offered a Val function solution in my
first posting in this thread (although I structured it as a self-contained
macro as opposed to a macro-to-be-used-as-a-formula). My post here, against
your message, restricted the assumptions to the same ones you used for your
regular expression function solution.

Rick



  #16   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default removing alpha

On Mon, 4 Jun 2007 01:16:30 -0400, "Rick Rothstein \(MVP - VB\)"
wrote:

If we accept the premise, from his example, that the digits always come
first,
and also that he wants a NUMBER returned, we could shorten the UDF even
further:

Function RemAlpha(str)
RemAlpha = Val(str)
End Function


Yes, I addressed that assumption and offered a Val function solution in my
first posting in this thread (although I structured it as a self-contained
macro as opposed to a macro-to-be-used-as-a-formula). My post here, against
your message, restricted the assumptions to the same ones you used for your
regular expression function solution.

Rick


Looks like I posted at the same time acknowledging.

Why, in your UDF, do you first replace the non-digits with spaces, and then
replace the spaces?

Why not something like:

If Mid$(str, X, 1) Like "[!0-9]" Then
remalpha = remalpha & Mid$(str, X)
end if


--ron
Reply
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
Removing Trailing Alpha? ConfusedNHouston Excel Discussion (Misc queries) 8 June 1st 07 02:16 AM
Removing Trailing Alpha - Something I Forgot ConfusedNHouston Excel Discussion (Misc queries) 1 June 1st 07 12:37 AM
--alpha = 0.10, alpha = 0.05, and/or Dave F Excel Discussion (Misc queries) 4 November 28th 06 11:25 PM
how do you add up alpha??? muttley23 Excel Worksheet Functions 1 April 21st 06 03:31 PM
The colums changed from alpha to numeric how do you make it alpha worldmade Excel Discussion (Misc queries) 2 May 26th 05 03:44 PM


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