Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Repost - Extracting a table from a cell

Mornin' all,

I've got a table with company details on it, then a list
of product codes that the company sells.
I want to write a new table, for the moment just a new
worksheet would be great, based on the product codes.

I'd like to take a record like this (where the ' - ' bit
specifies a new column):

R1FQ33 - 20780P,41930P
R7D41L - 52100S,84500S,42230P,45210P

and turn it into this:

R1FQ33 - 20780 - P
R1FQ33 - 41930 - P
R7D41L - 52100 - S
R7D41L - 84500 - S
R7D41L - 42230 - P
R7D41L - 45210 - P

There can be any number of items in the second column but they're always
separated by a comma. Each item in the cell can be four or five numbers
followed by a letter.

I can't get my head round how I'm going to do this. Let alone make it work,
can anyone offer any sample code or pointers?

Thanks very much,
Foss
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Repost - Extracting a table from a cell

If you have xl2000 or later

Sub WriteData()
j = 0
set rng = Range(Cells(2,1),Cells(2,1).End(xldown)
set rng1 = selection.parent.next.Range("A2")
for each cell in rng
sID = cell.Value
v = Split(cell.offset(0,1).Value,",")
for i = lbound(v) to ubound(v)
rng1.offset(j,0).Value = sID
rng1.offset(j,1).Value = "'" & left(v(i),len(v(i))-1)
rng1.offset(j,2).Value = Right(v(i),1)
j = j + 1
Next i
Next cell
End Sub

Select the sheet with you numbers as the active sheet. The results are
written to the next sheet in the tab order (so this should be blank).

It starts in A2 of each sheet (adjust to suit). It puts the numbers in as
Text so you don't lose any leading zeros. If you want them stored as
numbers, then remove the "'" & from the code above.

--
Regards,
Tom Ogilvy


"Foss" wrote in message
...
Mornin' all,

I've got a table with company details on it, then a list
of product codes that the company sells.
I want to write a new table, for the moment just a new
worksheet would be great, based on the product codes.

I'd like to take a record like this (where the ' - ' bit
specifies a new column):

R1FQ33 - 20780P,41930P
R7D41L - 52100S,84500S,42230P,45210P

and turn it into this:

R1FQ33 - 20780 - P
R1FQ33 - 41930 - P
R7D41L - 52100 - S
R7D41L - 84500 - S
R7D41L - 42230 - P
R7D41L - 45210 - P

There can be any number of items in the second column but they're always
separated by a comma. Each item in the cell can be four or five numbers
followed by a letter.

I can't get my head round how I'm going to do this. Let alone make it

work,
can anyone offer any sample code or pointers?

Thanks very much,
Foss



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Repost - Extracting a table from a cell


Tom,
you've beat me to it..

Sub ParseAndDump()
Dim rowSrc As Range
Dim rngDst As Range
Dim itm As Variant
Dim r As Long
'adjust Source and destination to suit...
Set rngDst = Worksheets(2).Cells(1)
For Each rowSrc In Worksheets(1).Cells(1).CurrentRegion.Rows
For Each itm In Split(rowSrc.Cells(1, 2), ",")
rngDst.Offset(r).Resize(1, 3) = Array( _
rowSrc.Cells(1, 1), Val(itm), Right(itm, 1))
r = r + 1
Next
Next

End Sub




--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Tom Ogilvy wrote :

If you have xl2000 or later

Sub WriteData()
j = 0
set rng = Range(Cells(2,1),Cells(2,1).End(xldown)
set rng1 = selection.parent.next.Range("A2")
for each cell in rng
sID = cell.Value
v = Split(cell.offset(0,1).Value,",")
for i = lbound(v) to ubound(v)
rng1.offset(j,0).Value = sID
rng1.offset(j,1).Value = "'" & left(v(i),len(v(i))-1)
rng1.offset(j,2).Value = Right(v(i),1)
j = j + 1
Next i
Next cell
End Sub

Select the sheet with you numbers as the active sheet. The results
are written to the next sheet in the tab order (so this should be
blank).

It starts in A2 of each sheet (adjust to suit). It puts the numbers
in as Text so you don't lose any leading zeros. If you want them
stored as numbers, then remove the "'" & from the code above.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Repost - Extracting a table from a cell

As ever, you've helped me no end!

Thanks very much to both of you. Much appreciated!

Cheers,
Pete

"Foss" wrote:

Mornin' all,

I've got a table with company details on it, then a list
of product codes that the company sells.
I want to write a new table, for the moment just a new
worksheet would be great, based on the product codes.

I'd like to take a record like this (where the ' - ' bit
specifies a new column):

R1FQ33 - 20780P,41930P
R7D41L - 52100S,84500S,42230P,45210P

and turn it into this:

R1FQ33 - 20780 - P
R1FQ33 - 41930 - P
R7D41L - 52100 - S
R7D41L - 84500 - S
R7D41L - 42230 - P
R7D41L - 45210 - P

There can be any number of items in the second column but they're always
separated by a comma. Each item in the cell can be four or five numbers
followed by a letter.

I can't get my head round how I'm going to do this. Let alone make it work,
can anyone offer any sample code or pointers?

Thanks very much,
Foss

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
Zero in cell where it is linked to a blank cell - repost texansgal Excel Worksheet Functions 4 May 27th 09 05:59 PM
Extracting Table Data maria Excel Worksheet Functions 1 May 22nd 09 06:37 PM
extracting data from a table mitch Excel Discussion (Misc queries) 3 January 25th 08 10:43 PM
PIVOT TABLE HELP (PLEASE) - REPOST scubadiver Excel Discussion (Misc queries) 1 October 11th 07 10:26 AM
Repost: Pivot Table flow23 Excel Discussion (Misc queries) 0 February 17th 06 04:42 PM


All times are GMT +1. The time now is 04:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"