On Fri, 21 May 2010 04:00:01 -0700, Seperate text and number <Seperate text and
Hi,
I have some data in cell (A1) which is alpha numeric, from this data I want
number and text in seperate cells (B1) and (C1) respectively per the below
example.
A B C
Raw Data Numbers Text
asho344555k123 344555123 ashok
123ab47 12347 ab
1affu123 1123 affu
Thanks
Afroz
Here is a macro that will do that.
To enter this Macro (Sub), <alt-F11> opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.
To use this Macro (Sub), first select the range you wish to parse.
Then <alt-F8> opens the macro dialog box. Select the macro by name, and <RUN>.
==============================================
Option Explicit
Sub SplitNumsText()
Dim c As Range, rg As Range
Dim re As Object, mc As Object
Set rg = Selection
Set re = CreateObject("vbscript.regexp")
re.Global = True
For Each c In rg
'format set to text to prevent Excel from using Scientific
'notation, dropping leading zero's, or rounding numbers
'with more than 15 digits
Range(c.Offset(0, 1), c.Offset(0, 2)).NumberFormat = "@"
re.Pattern = "\d" 'remove all digits
c.Offset(0, 1).Value = re.Replace(c.Text, "")
re.Pattern = "\D" 'remove all non-digits
c.Offset(0, 2).Value = re.Replace(c.Text, "")
Next c
End Sub
===============================
--ron