View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Need to conditionally duplicate rows

Some ideas...
Use the TextToColumns method and separate the text into
columns on a worksheet (using a space as the delimiter).
Then loop thru each row and check for those rows with more than two
columns of data.
Insert the appropriate number of extra rows and copy the extra
column data into the new rows. (then delete the extra columns)

Another way might be to use the Split function on each cell.
It returns a zero based array containing strings that were separated by a
specified delimiter.
If the upper bound of the array is greater than one then insert
additional row(s) into the worksheet and copy the appropriate array
elements to the new row(s).
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Martin Leese"
wrote in message
Hi,
Not sure if this is the correct group or not.
I need to massage an Excel spreadsheet.
Specifically, if a cell in a column contains
more than one element (separated by commas)
then I need to duplicate that row with one
element in each row. For example, I want to
convert this:
Stuff1 an element
Stuff2 one element, two element
Stuff3 another element

into this:
Stuff1 an element
Stuff2 one element
Stuff2 two element
Stuff3 another element

where "Stuff1" is in column 1, and
"an element" is in column 2.

Any ideas how I can do this? I can program
in more languages than I care to remember,
but have never used Visual Basic. Would
Visual Basic be able to do this, and where
might I find an example of something similar.

The spreadsheet has thousands of rows with
hundreds of rows which need to be duplicated.
Doing it by hand would therefore be a last
resort.

Many thanks for any help you can give.
--
Regards,
Martin Leese
E-mail: LID
Web:
http://members.tripod.com/martin_leese/