Please help with loop
I need all the rows which contain data to repeat a certain number of
times. My attempt works perfectly for the first row, but stops there. Sub Try() Range("G2").Select StartVal = Val(InputBox("Enter how many lines per order: ")) Do While Not IsEmpty(ActiveCell.Value) For counter = 1 To (StartVal - 1) ActiveCell.EntireRow.Copy ActiveCell.Offset(1).EntireRow.Insert ActiveCell.Offset(1).EntireRow.PasteSpecial Next counter Loop End Sub Thanks for any help. Mike |
You have another reply at your other thread.
Mike C wrote: I need all the rows which contain data to repeat a certain number of times. My attempt works perfectly for the first row, but stops there. Sub Try() Range("G2").Select StartVal = Val(InputBox("Enter how many lines per order: ")) Do While Not IsEmpty(ActiveCell.Value) For counter = 1 To (StartVal - 1) ActiveCell.EntireRow.Copy ActiveCell.Offset(1).EntireRow.Insert ActiveCell.Offset(1).EntireRow.PasteSpecial Next counter Loop End Sub Thanks for any help. Mike -- Dave Peterson |
Mike,
You'll need to Select the next cell. ... ActiveCell.Offset(1,0).Select Next Counter -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Mike C" wrote in message ... I need all the rows which contain data to repeat a certain number of times. My attempt works perfectly for the first row, but stops there. Sub Try() Range("G2").Select StartVal = Val(InputBox("Enter how many lines per order: ")) Do While Not IsEmpty(ActiveCell.Value) For counter = 1 To (StartVal - 1) ActiveCell.EntireRow.Copy ActiveCell.Offset(1).EntireRow.Insert ActiveCell.Offset(1).EntireRow.PasteSpecial Next counter Loop End Sub Thanks for any help. Mike |
Does this work?
Sub InsertCopydownRows() X = InputBox("How Many") fr = 2 lr = Cells(Rows.Count, "g").End(xlUp).row For i = lr To fr Step -1 Rows(i + 1).Resize(X).EntireRow.Insert Rows(i).Copy Rows(i + 1).Resize(X) Next i End Sub -- Don Guillett SalesAid Software "Mike C" wrote in message ... I need all the rows which contain data to repeat a certain number of times. My attempt works perfectly for the first row, but stops there. Sub Try() Range("G2").Select StartVal = Val(InputBox("Enter how many lines per order: ")) Do While Not IsEmpty(ActiveCell.Value) For counter = 1 To (StartVal - 1) ActiveCell.EntireRow.Copy ActiveCell.Offset(1).EntireRow.Insert ActiveCell.Offset(1).EntireRow.PasteSpecial Next counter Loop End Sub Thanks for any help. Mike |
All times are GMT +1. The time now is 09:43 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com