Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
none
 
Posts: n/a
Default How to Copy & Paste Rows?

Please help with my lame attempt to have the user enter how many times a
row needs to be repeated. Here's the scenario: I have a
spreadsheet with weeks of the year for each year and need each one
repeated a certain number of times.


Sub SOCal()
'
' SOCal Macro

Range("G2").Select
StartVal = Val(InputBox("Enter how many lines per order: "))
Set currentCell = Worksheets("Sheet1").Range("G2")
Do While Not IsEmpty(currentCell)
For counter = 1 To (StartVal - 1)
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1, 0).EntireRow.Insert
ActiveCell.EntireRow.Paste
ActiveCell.Offset(1, 0).Select
Next counter
Loop

End Sub


Thanks for any help.

Mike
  #2   Report Post  
none
 
Posts: n/a
Default

none wrote:
Please help with my lame attempt to have the user enter how many times a
row needs to be repeated. Here's the scenario: I have a spreadsheet
with weeks of the year for each year and need each one repeated a
certain number of times.


Sub SOCal()
'
' SOCal Macro

Range("G2").Select
StartVal = Val(InputBox("Enter how many lines per order: "))
Set currentCell = Worksheets("Sheet1").Range("G2")
Do While Not IsEmpty(currentCell)
For counter = 1 To (StartVal - 1)
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1, 0).EntireRow.Insert
ActiveCell.EntireRow.Paste
ActiveCell.Offset(1, 0).Select
Next counter
Loop

End Sub


Thanks for any help.

Mike



Here's the scenario: I have a spreadsheet with weeks of the year for
each row and need each one repeated a certain number of times.
  #3   Report Post  
none
 
Posts: n/a
Default

none wrote:
Please help with my lame attempt to have the user enter how many times a
row needs to be repeated. Here's the scenario: I have a spreadsheet
with weeks of the year for each year and need each one repeated a
certain number of times.


Sub SOCal()
'
' SOCal Macro

Range("G2").Select
StartVal = Val(InputBox("Enter how many lines per order: "))
Set currentCell = Worksheets("Sheet1").Range("G2")
Do While Not IsEmpty(currentCell)
For counter = 1 To (StartVal - 1)
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1, 0).EntireRow.Insert
ActiveCell.EntireRow.Paste
ActiveCell.Offset(1, 0).Select
Next counter
Loop

End Sub


Thanks for any help.

Mike


Here's the scenario: I have a spreadsheet with weeks of the year for
each row and need each one repeated a certain number of times.
  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

David McRitchie has some code you can steal.

He even shows how to copy the formulas, but clear out the constants.

http://www.mvps.org/dmcritchie/excel/insrtrow.htm
look for: #insrtrow



none wrote:

Please help with my lame attempt to have the user enter how many times a
row needs to be repeated. Here's the scenario: I have a
spreadsheet with weeks of the year for each year and need each one
repeated a certain number of times.

Sub SOCal()
'
' SOCal Macro

Range("G2").Select
StartVal = Val(InputBox("Enter how many lines per order: "))
Set currentCell = Worksheets("Sheet1").Range("G2")
Do While Not IsEmpty(currentCell)
For counter = 1 To (StartVal - 1)
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1, 0).EntireRow.Insert
ActiveCell.EntireRow.Paste
ActiveCell.Offset(1, 0).Select
Next counter
Loop

End Sub

Thanks for any help.

Mike


--

Dave Peterson
  #5   Report Post  
Mike C
 
Posts: n/a
Default

Dave Peterson wrote:
David McRitchie has some code you can steal.

He even shows how to copy the formulas, but clear out the constants.

http://www.mvps.org/dmcritchie/excel/insrtrow.htm
look for: #insrtrow



none wrote:

Please help with my lame attempt to have the user enter how many times a
row needs to be repeated. Here's the scenario: I have a
spreadsheet with weeks of the year for each year and need each one
repeated a certain number of times.

Sub SOCal()
'
' SOCal Macro

Range("G2").Select
StartVal = Val(InputBox("Enter how many lines per order: "))
Set currentCell = Worksheets("Sheet1").Range("G2")
Do While Not IsEmpty(currentCell)
For counter = 1 To (StartVal - 1)
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1, 0).EntireRow.Insert
ActiveCell.EntireRow.Paste
ActiveCell.Offset(1, 0).Select
Next counter
Loop

End Sub

Thanks for any help.

Mike



Thanks for the help Dave!

I have a problem with my loop. It only copies the first row & pastes it
the correct number of times, but I need it to do the same for all the
rows in the spreadsheet.

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,
Mike









  #6   Report Post  
Dave Peterson
 
Posts: n/a
Default

So you're essentially repeating every row a set number of times?

Try this against a copy:

Option Explicit
Sub testme()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim HowMany As Long
Dim wks As Worksheet

HowMany = Application.InputBox("How many rows to insert?", Type:=1)

If HowMany = 0 _
Or HowMany 100 Then
MsgBox "Please pick a nice number"
Exit Sub
End If

Set wks = ActiveSheet

With wks
FirstRow = 2 'stay away from headers???
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
.Rows(iRow + 1).Resize(HowMany).EntireRow.Insert
.Rows(iRow).Copy _
Destination:=.Rows(iRow + 1).Resize(HowMany)
Next iRow
End With

End Sub

Mike C wrote:

Dave Peterson wrote:
David McRitchie has some code you can steal.

He even shows how to copy the formulas, but clear out the constants.

http://www.mvps.org/dmcritchie/excel/insrtrow.htm
look for: #insrtrow



none wrote:

Please help with my lame attempt to have the user enter how many times a
row needs to be repeated. Here's the scenario: I have a
spreadsheet with weeks of the year for each year and need each one
repeated a certain number of times.

Sub SOCal()
'
' SOCal Macro

Range("G2").Select
StartVal = Val(InputBox("Enter how many lines per order: "))
Set currentCell = Worksheets("Sheet1").Range("G2")
Do While Not IsEmpty(currentCell)
For counter = 1 To (StartVal - 1)
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1, 0).EntireRow.Insert
ActiveCell.EntireRow.Paste
ActiveCell.Offset(1, 0).Select
Next counter
Loop

End Sub

Thanks for any help.

Mike



Thanks for the help Dave!

I have a problem with my loop. It only copies the first row & pastes it
the correct number of times, but I need it to do the same for all the
rows in the spreadsheet.

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,
Mike


--

Dave Peterson
  #7   Report Post  
Mike C
 
Posts: n/a
Default

Dave Peterson wrote:
So you're essentially repeating every row a set number of times?

Try this against a copy:

Option Explicit
Sub testme()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim HowMany As Long
Dim wks As Worksheet

HowMany = Application.InputBox("How many rows to insert?", Type:=1)

If HowMany = 0 _
Or HowMany 100 Then
MsgBox "Please pick a nice number"
Exit Sub
End If

Set wks = ActiveSheet

With wks
FirstRow = 2 'stay away from headers???
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
.Rows(iRow + 1).Resize(HowMany).EntireRow.Insert
.Rows(iRow).Copy _
Destination:=.Rows(iRow + 1).Resize(HowMany)
Next iRow
End With

End Sub

Mike C wrote:

Dave Peterson wrote:

David McRitchie has some code you can steal.

He even shows how to copy the formulas, but clear out the constants.

http://www.mvps.org/dmcritchie/excel/insrtrow.htm
look for: #insrtrow



none wrote:


Please help with my lame attempt to have the user enter how many times a
row needs to be repeated. Here's the scenario: I have a
spreadsheet with weeks of the year for each year and need each one
repeated a certain number of times.

Sub SOCal()
'
' SOCal Macro

Range("G2").Select
StartVal = Val(InputBox("Enter how many lines per order: "))
Set currentCell = Worksheets("Sheet1").Range("G2")
Do While Not IsEmpty(currentCell)
For counter = 1 To (StartVal - 1)
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1, 0).EntireRow.Insert
ActiveCell.EntireRow.Paste
ActiveCell.Offset(1, 0).Select
Next counter
Loop

End Sub

Thanks for any help.

Mike


Thanks for the help Dave!

I have a problem with my loop. It only copies the first row & pastes it
the correct number of times, but I need it to do the same for all the
rows in the spreadsheet.

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,
Mike



Awesome! Thanks a lot for your help.

Mike
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
In Excel, how do you copy and paste just the subtotals into anoth. mmiazga Excel Discussion (Misc queries) 4 February 13th 05 01:17 AM
Paste rows of numbers from Word into single Excel cell BecG Excel Discussion (Misc queries) 1 December 8th 04 04:55 PM
copy paste cell character limit Fred Excel Discussion (Misc queries) 1 December 2nd 04 08:58 PM
Copy and Paste Steve Excel Discussion (Misc queries) 2 December 2nd 04 12:35 AM
copy and paste G Excel Worksheet Functions 2 November 2nd 04 01:56 AM


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