Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ed Ed is offline
external usenet poster
 
Posts: 279
Default Extract texts & numbers from one cell into four cells

Hi there,

My query is on how to separate texts and numbers (including Item Code,
Product Names, Stock Sold and Stock Remain) from one cell into four
cells on the same worksheet.

1. The Item Code could have One to Four digits.
2. The Product Name is in various lengths, could have four words with
spacing in between.
3. Stock Sold and Stock Remain both could have a range between 0 and
9,999,999,999.99 (there will be no negative value)
4. The spacing between these four pieces of information could be varies as
well.

Example One:
Item Code: 1
Product Name: AAA
Stock Sold: 1
Stock Remain: 9,999,999,999,999.99

1 AAA 1.00 9,999,999,999,999.99

Example Two:
Item Code: 9999
Product Name: A B C D
Stock Sold: 9,999,999,999,999.99
Stock Remain: 1,000,000,000.00

9999 A B C D 9,999,999,999,999.99 1,000,000,000.00


Many thanks and really appreciate for your assistance!

Ed

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 367
Default Extract texts & numbers from one cell into four cells

Hi Ed

you can do following:
A1 is your weird cell (source)
B1: =LEFT(A1,FIND(" ",A1)-1)
C1: =MID(TRIM(A1),LEN(B1)+2,LEN(TRIM(A1))-LEN(B1)-LEN(D1)-LEN(E1)-3)
D1: =RIGHT(LEFT(TRIM(A1),LEN(TRIM(A1))-
LEN(E1)-1),LEN(LEFT(TRIM(A1),LEN(TRIM(A1))-LEN(E1)-1))-
LOOKUP(33000,FIND(" ",LEFT(TRIM(A1),LEN(TRIM(A1))-
LEN(E1)-1),ROW(A:A))))
E1: =RIGHT(TRIM(A1),LEN(TRIM(A1))-LOOKUP(33000,FIND("
",TRIM(A1),ROW(A:A))))

hth
Carlo

On Jan 24, 3:14 pm, Ed wrote:
Hi there,

My query is on how to separate texts and numbers (including "Item Code",
"Product Names", "Stock Sold" and "Stock Remain") from one cell into four
cells on the same worksheet.

1. The "Item Code" could have One to Four digits.
2. The "Product Name" is in various lengths, could have four words with
spacing in between.
3. "Stock Sold" and "Stock Remain" both could have a range between 0 and
9,999,999,999.99 (there will be no negative value)
4. The spacing between these four pieces of information could be varies as
well.

Example One:
Item Code: 1
Product Name: AAA
Stock Sold: 1
Stock Remain: 9,999,999,999,999.99

1 AAA 1.00 9,999,999,999,999.99

Example Two:
Item Code: 9999
Product Name: A B C D
Stock Sold: 9,999,999,999,999.99
Stock Remain: 1,000,000,000.00

9999 A B C D 9,999,999,999,999.99 1,000,000,000.00

Many thanks and really appreciate for your assistance!

Ed


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default Extract texts & numbers from one cell into four cells

On Wed, 23 Jan 2008 22:14:10 -0800, Ed wrote:

Hi there,

My query is on how to separate texts and numbers (including Item Code,
Product Names, Stock Sold and Stock Remain) from one cell into four
cells on the same worksheet.

1. The Item Code could have One to Four digits.
2. The Product Name is in various lengths, could have four words with
spacing in between.
3. Stock Sold and Stock Remain both could have a range between 0 and
9,999,999,999.99 (there will be no negative value)
4. The spacing between these four pieces of information could be varies as
well.

Example One:
Item Code: 1
Product Name: AAA
Stock Sold: 1
Stock Remain: 9,999,999,999,999.99

1 AAA 1.00 9,999,999,999,999.99

Example Two:
Item Code: 9999
Product Name: A B C D
Stock Sold: 9,999,999,999,999.99
Stock Remain: 1,000,000,000.00

9999 A B C D 9,999,999,999,999.99 1,000,000,000.00


Many thanks and really appreciate for your assistance!

Ed


Are your data entries all on one line within the cell? As in the above two
lines:

1 AAA 1.00 9,999,999,999,999.99
9999 A B C D 9,999,999,999,999.99 1,000,000,000.00

If so, the following Macro should do what you want. As written, it operates on
"Selection" and writes the split results into the four adjacent columns on the
same row.

If you want to replace the original data, see the instructions in the macro
comments in two areas.

================================================
Option Explicit

Sub SplitCodes()
Dim c As Range
Dim i As Long
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "(\d{1,4})\s+(.*?)\s+([0-9,.]+)\s+([0-9,.]+)$"
For Each c In Selection
'clear adjacent cells
'if replacing source column, change "c(1,5)" to "c(1,4)"
Range(c(1, 2), c(1, 5)).Clear
If re.test(Trim(c.Text)) = True Then
Set mc = re.Execute(Trim(c.Text))
For i = 0 To 3
'In line below, change "i+1" to "i" to replace source column
c.Offset(0, i + 1).Value = mc(0).submatches(i)
Next i
End If
Next c
End Sub
==============================================

To enter the macro <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.

To use it, select the range you wish to process. <alt<F8 opens the macro
dialog box. Select the SplitCodes macro and RUN.
--ron
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default Extract texts & numbers from one cell into four cells

On Thu, 24 Jan 2008 09:38:57 -0500, Ron Rosenfeld
wrote:

On Wed, 23 Jan 2008 22:14:10 -0800, Ed wrote:

Hi there,

My query is on how to separate texts and numbers (including Item Code,
Product Names, Stock Sold and Stock Remain) from one cell into four
cells on the same worksheet.

1. The Item Code could have One to Four digits.
2. The Product Name is in various lengths, could have four words with
spacing in between.
3. Stock Sold and Stock Remain both could have a range between 0 and
9,999,999,999.99 (there will be no negative value)
4. The spacing between these four pieces of information could be varies as
well.

Example One:
Item Code: 1
Product Name: AAA
Stock Sold: 1
Stock Remain: 9,999,999,999,999.99

1 AAA 1.00 9,999,999,999,999.99

Example Two:
Item Code: 9999
Product Name: A B C D
Stock Sold: 9,999,999,999,999.99
Stock Remain: 1,000,000,000.00

9999 A B C D 9,999,999,999,999.99 1,000,000,000.00


Many thanks and really appreciate for your assistance!

Ed


Are your data entries all on one line within the cell? As in the above two
lines:

1 AAA 1.00 9,999,999,999,999.99
9999 A B C D 9,999,999,999,999.99 1,000,000,000.00

If so, the following Macro should do what you want. As written, it operates on
"Selection" and writes the split results into the four adjacent columns on the
same row.

If you want to replace the original data, see the instructions in the macro
comments in two areas.

=============================================== =
Option Explicit

Sub SplitCodes()
Dim c As Range
Dim i As Long
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "(\d{1,4})\s+(.*?)\s+([0-9,.]+)\s+([0-9,.]+)$"
For Each c In Selection
'clear adjacent cells
'if replacing source column, change "c(1,5)" to "c(1,4)"
Range(c(1, 2), c(1, 5)).Clear
If re.test(Trim(c.Text)) = True Then
Set mc = re.Execute(Trim(c.Text))
For i = 0 To 3
'In line below, change "i+1" to "i" to replace source column
c.Offset(0, i + 1).Value = mc(0).submatches(i)
Next i
End If
Next c
End Sub
==============================================

To enter the macro <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.

To use it, select the range you wish to process. <alt<F8 opens the macro
dialog box. Select the SplitCodes macro and RUN.
--ron



Here's another version that does not use vbscript regular expressions:

---------------------------
Option Explicit

Sub SplitData()
Dim c As Range
Dim sTemp() As String
Dim sT As String
Dim i As Long
For Each c In Selection
Range(c(1, 2), c(1, 5)).Clear
sTemp = Split(Application.WorksheetFunction.Trim(c.Text))
If UBound(sTemp) = 3 Then
c.Offset(0, 1).Value = sTemp(0)
i = 1
sT = ""
Do Until i = UBound(sTemp) - 1
sT = sT & sTemp(i) & " "
i = i + 1
Loop
c.Offset(0, 2).Value = Trim(sT)
c.Offset(0, 3).Value = sTemp(UBound(sTemp) - 1)
c.Offset(0, 4).Value = sTemp(UBound(sTemp))
End If
Next c
End Sub
------------------------------------------------
--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
List of unique texts and numbers vsoler Excel Worksheet Functions 7 May 19th 07 06:47 PM
how to extract numbers from imported cell with text and numbers? jyin Excel Discussion (Misc queries) 3 March 28th 07 01:14 PM
Extract numbers from cells Orf Bartrop New Users to Excel 5 December 17th 06 08:04 AM
Conditional Formatting : Numbers & Texts Conflict nayinky Excel Worksheet Functions 3 August 8th 06 07:15 AM
convert numbers to texts sampath Excel Worksheet Functions 1 December 2nd 04 01:18 PM


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