Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 68
Default separating numbers from a alphanumeric cell

How to separate numbers from a alphanumeri cell.

For Eg: If a cell contains data as 1. Apple25orange50
The result should come as 25&50.
Eg: 2 . sdfldsj2535hlkfd2548dsfs36 - result should be as 2535&2548&36

There should be separator with "&" function.

Can any one guide me with the formula to use with "&" and without "&".
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default separating numbers from a alphanumeric cell

Can you live with a macro?

Public Sub StripAllAZs()
''strips out everything except numbers
'adds an ampersand between number sets
Dim myRange As Range
Dim cell As Range
Dim myStr As String
Dim i As Integer
With Application
.ScreenUpdating = False
.Calculation = xlManual
End With
On Error Resume Next
Set myRange = Range(ActiveCell.Address & "," & Selection.Address) _
.SpecialCells(xlCellTypeConstants)
If myRange Is Nothing Then Exit Sub
If Not myRange Is Nothing Then
For Each cell In myRange
myStr = cell.text
For i = 1 To Len(myStr)
If (Asc(UCase(Mid(myStr, i, 1))) < 48) Or _
(Asc(UCase(Mid(myStr, i, 1))) 57) Then
myStr = Left(myStr, i - 1) & " " & Mid(myStr, i + 1)
End If
Next i
cell.Value = Application.Trim(myStr)
Next cell
Selection.Replace What:=" ", Replacement:="&", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
'change Replacement:="&" to Replacement:="" if no separator wanted
End If
With Application
.Calculation = xlAutomatic
.ScreenUpdating = True
End With
End Sub


Gord Dibben MS Excel MVP

On Mon, 12 Mar 2007 10:24:15 -0700, Igneshwara reddy
wrote:

How to separate numbers from a alphanumeri cell.

For Eg: If a cell contains data as 1. Apple25orange50
The result should come as 25&50.
Eg: 2 . sdfldsj2535hlkfd2548dsfs36 - result should be as 2535&2548&36

There should be separator with "&" function.

Can any one guide me with the formula to use with "&" and without "&".


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,574
Default separating numbers from a alphanumeric cell

Gord, can you explain what this IF statement does:

If (Asc(UCase(Mid(myStr, i, 1))) < 48) Or _
(Asc(UCase(Mid(myStr, i, 1))) 57) Then
myStr = Left(myStr, i - 1) & " " & Mid(myStr, i + 1)
End If

Thanks,

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Gord Dibben" wrote:

Can you live with a macro?

Public Sub StripAllAZs()
''strips out everything except numbers
'adds an ampersand between number sets
Dim myRange As Range
Dim cell As Range
Dim myStr As String
Dim i As Integer
With Application
.ScreenUpdating = False
.Calculation = xlManual
End With
On Error Resume Next
Set myRange = Range(ActiveCell.Address & "," & Selection.Address) _
.SpecialCells(xlCellTypeConstants)
If myRange Is Nothing Then Exit Sub
If Not myRange Is Nothing Then
For Each cell In myRange
myStr = cell.text
For i = 1 To Len(myStr)
If (Asc(UCase(Mid(myStr, i, 1))) < 48) Or _
(Asc(UCase(Mid(myStr, i, 1))) 57) Then
myStr = Left(myStr, i - 1) & " " & Mid(myStr, i + 1)
End If
Next i
cell.Value = Application.Trim(myStr)
Next cell
Selection.Replace What:=" ", Replacement:="&", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
'change Replacement:="&" to Replacement:="" if no separator wanted
End If
With Application
.Calculation = xlAutomatic
.ScreenUpdating = True
End With
End Sub


Gord Dibben MS Excel MVP

On Mon, 12 Mar 2007 10:24:15 -0700, Igneshwara reddy
wrote:

How to separate numbers from a alphanumeri cell.

For Eg: If a cell contains data as 1. Apple25orange50
The result should come as 25&50.
Eg: 2 . sdfldsj2535hlkfd2548dsfs36 - result should be as 2535&2548&36

There should be separator with "&" function.

Can any one guide me with the formula to use with "&" and without "&".



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default separating numbers from a alphanumeric cell

On Mon, 12 Mar 2007 10:24:15 -0700, Igneshwara reddy
wrote:

How to separate numbers from a alphanumeri cell.

For Eg: If a cell contains data as 1. Apple25orange50
The result should come as 25&50.
Eg: 2 . sdfldsj2535hlkfd2548dsfs36 - result should be as 2535&2548&36

There should be separator with "&" function.

Can any one guide me with the formula to use with "&" and without "&".



To separate out the numbers and join them with the &, you could download and
install Longre's free morefunc.xll add-in from http://xcell05.free.fr and then
use one of these formulas:


=REGEX.SUBSTITUTE(A1,"(^[A-Z]+)|([A-Z]+)","[1=,2=&]",,,FALSE)

=MCONCAT(REGEX.MID(A1,"\d+",INTVECTOR(REGEX.COUNT( A1,"\d+"),1)),"&")



What do you mean for a formula "without &"?

If you mean just the numbers with no separator, then:

=REGEX.SUBSTITUTE(A1,"\D")

will do that.


--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
extract numbers from a alphanumeric cell Igneshwara reddy Excel Worksheet Functions 4 February 27th 07 06:24 PM
Function to extract numbers from an alphanumeric cell diana Excel Worksheet Functions 4 March 13th 06 09:55 AM
separating numbers and letters from alphanumeric cell contents PH Excel Worksheet Functions 10 September 3rd 05 12:15 PM
Separating Numbers Himu Excel Worksheet Functions 7 June 2nd 05 05:20 AM
Sorting alphanumeric numbers maurice.centner Excel Discussion (Misc queries) 2 May 6th 05 02:00 AM


All times are GMT +1. The time now is 02:47 PM.

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"