Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to copy and paste a user selected number of rows

Hi,

I am trying to create a macro that copies a row (that contains
formulas) and pastes this row a chosen number of times, using an input
box.

Can anyone help me?

Many thanks in advance!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Macro to copy and paste a user selected number of rows

bozwero:

You don't appear to be able to copy a selection and then run a macro so try
this:

Sub PasteRowANumberOfTimes()
Dim i As Long
Dim rDstStart As Long, rDstNr As Long, rSrc As Long

On Error GoTo error_line

rSrc = InputBox("Row to copy?", "Row Copier...", 1)
rDstStart = InputBox("First row to paste it to?", "Row Paster...", 1)
rDstNr = InputBox("How many times shall I paste it?", "Row Paster...", 1)

Rows(rSrc).Copy

For i = 0 To rDstNr - 1 Step 1
Rows(rDstStart + i).PasteSpecial xlPasteAll,
xlPasteSpecialOperationNone
Next i
Application.CutCopyMode = False
Cells(rDstStart, 1).Select
Exit Sub
error_line:
MsgBox "Error pasting rows, check", vbOKOnly

End Sub



--
Hope this helps
Martin Fishlock


"bozwero" wrote:

Hi,

I am trying to create a macro that copies a row (that contains
formulas) and pastes this row a chosen number of times, using an input
box.

Can anyone help me?

Many thanks in advance!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to copy and paste a user selected number of rows

Hi Martin,

Many thanks for the reply and the suggestion. However, i don't think
this is what i am looking for. Basically i have a spreadsheet template
that has a limited number of rows (50) to enter data into. The user
may need to use more than 50 rows of data, and so i would like the user
to be able to run a macro that asks them how many additional rows they
need, and paste these into the spreadsheet.

I need the macro to copy one row, then ask the user to "Enter number of
rows to add", and then from this, paste the row below the copied row
the chosen number of times.

Does this make more sense?

Thanks again.
Bozwero.


Martin Fishlock wrote:
bozwero:

You don't appear to be able to copy a selection and then run a macro so try
this:

Sub PasteRowANumberOfTimes()
Dim i As Long
Dim rDstStart As Long, rDstNr As Long, rSrc As Long

On Error GoTo error_line

rSrc = InputBox("Row to copy?", "Row Copier...", 1)
rDstStart = InputBox("First row to paste it to?", "Row Paster...", 1)
rDstNr = InputBox("How many times shall I paste it?", "Row Paster...", 1)

Rows(rSrc).Copy

For i = 0 To rDstNr - 1 Step 1
Rows(rDstStart + i).PasteSpecial xlPasteAll,
xlPasteSpecialOperationNone
Next i
Application.CutCopyMode = False
Cells(rDstStart, 1).Select
Exit Sub
error_line:
MsgBox "Error pasting rows, check", vbOKOnly

End Sub



--
Hope this helps
Martin Fishlock


"bozwero" wrote:

Hi,

I am trying to create a macro that copies a row (that contains
formulas) and pastes this row a chosen number of times, using an input
box.

Can anyone help me?

Many thanks in advance!



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
copy selected rows to second worksheet (NOT Cut + Paste) gyrra New Users to Excel 2 June 4th 10 09:05 PM
Macro to copy & paste-special-values data to selected worksheets tomhelle Excel Discussion (Misc queries) 1 May 5th 10 02:00 PM
Copy a selected number of rows Eric S. Excel Discussion (Misc queries) 4 June 25th 07 08:23 AM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Excel Programming 1 October 15th 04 01:16 PM
Macro to copy and past selected rows only... Jules[_4_] Excel Programming 1 April 14th 04 02:31 PM


All times are GMT +1. The time now is 07:57 PM.

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"