Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Create multiple copies of rows based on a cell value

I'm trying to create an input file for a mail merge that will create multiple
copies of rows based on a cell value. For example my sheet1 has:
name address qty
henry 123 anystreet 5

I need a sheet2 that contains 5, (the qty), rows of the name and address.
Each record may have a different qty.

Hope I have explained this well enough.

TIA,
Henry
  #2   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Create multiple copies of rows based on a cell value

Henryl,

Try this:

Option Explicit
Sub temp()
Dim LastRow As Long
Dim Qty As Integer
Dim i As Long
Dim j As Long
Dim k As Long

j = 2
LastRow = Sheets("Sheet1").Cells(65536, 1).End(xlUp).Row
For i = 2 To LastRow
With Sheets("Sheet1")
Qty = Cells(i, 3)
.Range(Cells(i, 1), Cells(i, 2)).Copy
End With
With Sheets("Sheet2")
For k = j To j + Qty - 1
.Range(.Cells(k, 1), .Cells(k, 2)).PasteSpecial
Next k
End With
j = j + Qty
Next i
End Sub

Art

"henryl" wrote:

I'm trying to create an input file for a mail merge that will create multiple
copies of rows based on a cell value. For example my sheet1 has:
name address qty
henry 123 anystreet 5

I need a sheet2 that contains 5, (the qty), rows of the name and address.
Each record may have a different qty.

Hope I have explained this well enough.

TIA,
Henry

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Create multiple copies of rows based on a cell value

Sub Test()
Dim iLastRow As Long
Dim iRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
iRow = 1
For i = 1 To iLastRow
Range("A" & i & ":B" & i).Copy Worksheets("Sheet2") _
.Range("A" & iRow & ":B" & iRow + Range("C" & i).Value - 1)
iRow = iRow + Range("C" & i).Value
Next i

End Sub



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"henryl" wrote in message
...
I'm trying to create an input file for a mail merge that will create

multiple
copies of rows based on a cell value. For example my sheet1 has:
name address qty
henry 123 anystreet 5

I need a sheet2 that contains 5, (the qty), rows of the name and address.
Each record may have a different qty.

Hope I have explained this well enough.

TIA,
Henry



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
Lookup & return multiple rows based on cell value Stacie2410 Excel Worksheet Functions 3 January 19th 10 04:36 PM
why does excel create multiple copies (as many as 18) of a file? Beezie Excel Discussion (Misc queries) 6 August 11th 05 03:55 PM
generate multiple rows based on cell value Theresa Excel Worksheet Functions 0 May 25th 05 11:18 PM
Create a report with selected rows based on the content in a cell ThirdTim New Users to Excel 1 May 5th 05 05:18 PM
Why does Excel create multiple copies of the same file? TJRUFF Excel Discussion (Misc queries) 2 January 27th 05 08:43 PM


All times are GMT +1. The time now is 07:33 AM.

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"