Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Seperating Data from a cell to a row

Hello experts!

I have been building a listing of all the cars that certain parts in our
inventory fit. The format of the sheet looks like this....
Column A - Part #, Column B - Item Description, Column C - Car Models the
part fits

I started building this list by seperating the different types of models by
a comma, here is an example of line.

Part # Item Description Car Models
9Y4537 Bolt Cabrio, Golf, GTI,
Passat

Now the IS department tells me in order to load the car types into our
computer system the car types listed in Col. C have to be on their own row,
in orther words it should look like this

Part # Item Description Car Models
9Y4537 Bolt Cabrio
9Y4537 Bolt Golf
9Y4537 Bolt GTI
9Y4537 Bolt Passat

You can see my obvious delemma, as the # of parts I have is around 1000, and
the # of seperate lines I would need to create is probably in the 10's of
thousands.

Is there a way to create a VBA script that could take the data from Column C
in sheet 1 (the original list with car types seperated by commas), and on
sheet 2 seperate out the data in individual rows like I demonstrated above?

I know its unlikely, but I've put about a month's worth of work into this
project, and to do this seperation by hand would take a whole extra month.

I hope you can help!

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Seperating Data from a cell to a row

This may work for you:

Option Explicit
Sub testme()

Dim CurWks As Worksheet
Dim NewWks As Worksheet

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim mySplit As Variant
Dim oRow As Long
Dim TotalRows As Long

Set CurWks = Worksheets("sheet1")
Set NewWks = Worksheets.Add

With CurWks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

oRow = 1
For iRow = FirstRow To LastRow
mySplit = Split97(Application.Substitute _
(.Cells(iRow, "C").Value, " ", ""), ",")

TotalRows = UBound(mySplit) - LBound(mySplit) + 1

NewWks.Cells(oRow, "A").Resize(TotalRows, 1).Value _
= .Cells(iRow, "A").Value

NewWks.Cells(oRow, "B").Resize(TotalRows, 1).Value _
= .Cells(iRow, "B").Value

NewWks.Cells(oRow, "C").Resize(TotalRows, 1).Value _
= Application.Transpose(mySplit)

oRow = oRow + TotalRows
Next iRow
End With
End Sub

Function Split97(sStr As String, sdelim As String) As Variant
'from Tom Ogilvy
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function


DA@PD wrote:

Hello experts!

I have been building a listing of all the cars that certain parts in our
inventory fit. The format of the sheet looks like this....
Column A - Part #, Column B - Item Description, Column C - Car Models the
part fits

I started building this list by seperating the different types of models by
a comma, here is an example of line.

Part # Item Description Car Models
9Y4537 Bolt Cabrio, Golf, GTI,
Passat

Now the IS department tells me in order to load the car types into our
computer system the car types listed in Col. C have to be on their own row,
in orther words it should look like this

Part # Item Description Car Models
9Y4537 Bolt Cabrio
9Y4537 Bolt Golf
9Y4537 Bolt GTI
9Y4537 Bolt Passat

You can see my obvious delemma, as the # of parts I have is around 1000, and
the # of seperate lines I would need to create is probably in the 10's of
thousands.

Is there a way to create a VBA script that could take the data from Column C
in sheet 1 (the original list with car types seperated by commas), and on
sheet 2 seperate out the data in individual rows like I demonstrated above?

I know its unlikely, but I've put about a month's worth of work into this
project, and to do this seperation by hand would take a whole extra month.

I hope you can help!

Thanks


--

Dave Peterson
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
Formula for seperating data eechris Excel Discussion (Misc queries) 2 January 27th 10 10:54 PM
Seperating text within a cell Alan Excel Discussion (Misc queries) 1 January 10th 08 09:48 PM
seperating data from one cell to multiple cells? Kitti Excel Worksheet Functions 5 July 28th 07 10:27 AM
Seperating Data From Lists JF[_2_] Excel Worksheet Functions 2 April 23rd 07 12:29 PM
Seperating Data within cells Tennisgirl Excel Discussion (Misc queries) 2 July 12th 05 05:00 PM


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