I want to duplicate rows

  • Thread starter Thread starter tsoussi
  • Start date Start date
T

tsoussi

my data base contains 1005 rows with various medical information (10
columns) One of the column corresponds to an occurence number and I
need to duplicate each row by this number

ex row 1, this number is 642 , therefore, I need that row 1 is
duplicated 642 times
row 2, this number is 55, then 55 duplication and so on

the target can be a new sheet

is it possible ?

it will help

thank you

Pr Soussi
Paris
 
Copy the code below into a macro.

Assumes two worksheets 'Worksheet1' (source data) and
Worksheet2' (target data). Substitute worksheet names if
required.

Assumes 21 rows in source data (substitute with correct
number of rows)

Assumes 10 columns and required number of rows stored in
column 10 of Worksheet1

-----------------------------------------------------
Sub CreateData()

Dim intRowsCreated, intRows, IntCurrentRow As Integer
Dim intColumnLoop, intNewRows As Integer

Sheets("Worksheet1").Select
For IntCurrentRow = 1 To 21
intNewRows = Cells(IntCurrentRow, 10)
Sheets("Worksheet2").Select
For intRows = 1 To intNewRows
For intColumnLoop = 1 To 10
Cells(intRowsCreated + 1, intColumnLoop) =
Sheets("Worksheet1").Cells(IntCurrentRow, intColumnLoop)
Next
intRowsCreated = intRowsCreated + 1
Next
Sheets("Worksheet1").Select
Next

End Sub
 
This may not be a concern, but make sure the total of the 1005 items isn't
greater than 65,536! Otherwise you'll run out of rows on the worksheet!

HTH
Steve
 
Back
Top