![]() |
Copying and inserting lines
In my spreadsheet, I was wondering if I could set a macro to copy an entire
row, ask me how many copies of the line I would like to make, and paste them underneath the original line. Any help would be greatly appriciated! |
Copying and inserting lines
More info but a macro using inputbox, find etc
Sub copyrows()'use FIND to find the row numrows = InputBox("Number of rows") + 1 Rows(ActiveCell.Row).Copy ActiveCell.Resize(numrows) End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "teo410" wrote in message ... In my spreadsheet, I was wondering if I could set a macro to copy an entire row, ask me how many copies of the line I would like to make, and paste them underneath the original line. Any help would be greatly appriciated! |
Copying and inserting lines
Click on any cell in the row and run:
Sub RowMaker() Dim r As Range, n As Long, nxtrow As Long, r2 As Range Set r = ActiveCell.EntireRow nxtrow = r.Row + 1 n = Application.InputBox(prompt:="How many rows", Type:=1) Set r2 = Range("A" & nxtrow & ":A" & nxtrow + n - 1) r.Copy r2 End Sub -- Gary''s Student - gsnu200860 "teo410" wrote: In my spreadsheet, I was wondering if I could set a macro to copy an entire row, ask me how many copies of the line I would like to make, and paste them underneath the original line. Any help would be greatly appriciated! |
Copying and inserting lines
This is great but I need to INSERT not PASTE the rows in otherwise it pastes
over other information. "Gary''s Student" wrote: Click on any cell in the row and run: Sub RowMaker() Dim r As Range, n As Long, nxtrow As Long, r2 As Range Set r = ActiveCell.EntireRow nxtrow = r.Row + 1 n = Application.InputBox(prompt:="How many rows", Type:=1) Set r2 = Range("A" & nxtrow & ":A" & nxtrow + n - 1) r.Copy r2 End Sub -- Gary''s Student - gsnu200860 "teo410" wrote: In my spreadsheet, I was wondering if I could set a macro to copy an entire row, ask me how many copies of the line I would like to make, and paste them underneath the original line. Any help would be greatly appriciated! |
Copying and inserting lines
Works great thanks!
Just an additional thought, how could I get the macro to put a border at the bottom of the last row inserted up to column N? "Don Guillett" wrote: Sub copyrows() numrows = InputBox("Number of rows") 'Rows(ActiveCell.Row).Copy ActiveCell.Resize(numrows) Rows(ActiveCell.Row).Copy ActiveCell.Resize(numrows).Insert Application.CutCopyMode = False End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "teo410" wrote in message ... This is great but I need to INSERT not PASTE the rows in otherwise it pastes over other information. "Gary''s Student" wrote: Click on any cell in the row and run: Sub RowMaker() Dim r As Range, n As Long, nxtrow As Long, r2 As Range Set r = ActiveCell.EntireRow nxtrow = r.Row + 1 n = Application.InputBox(prompt:="How many rows", Type:=1) Set r2 = Range("A" & nxtrow & ":A" & nxtrow + n - 1) r.Copy r2 End Sub -- Gary''s Student - gsnu200860 "teo410" wrote: In my spreadsheet, I was wondering if I could set a macro to copy an entire row, ask me how many copies of the line I would like to make, and paste them underneath the original line. Any help would be greatly appriciated! |
Copying and inserting lines
Sub copyrows()
numrows = InputBox("Number of rows") 'Rows(ActiveCell.Row).Copy ActiveCell.Resize(numrows) Rows(ActiveCell.Row).Copy ActiveCell.Resize(numrows).Insert Application.CutCopyMode = False Range(Cells(ActiveCell.Row, "a"), _ Cells(ActiveCell.Row + numrows, "n")) _ ..BorderAround Weight:=xlThick End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "teo410" wrote in message ... Works great thanks! Just an additional thought, how could I get the macro to put a border at the bottom of the last row inserted up to column N? "Don Guillett" wrote: Sub copyrows() numrows = InputBox("Number of rows") 'Rows(ActiveCell.Row).Copy ActiveCell.Resize(numrows) Rows(ActiveCell.Row).Copy ActiveCell.Resize(numrows).Insert Application.CutCopyMode = False End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "teo410" wrote in message ... This is great but I need to INSERT not PASTE the rows in otherwise it pastes over other information. "Gary''s Student" wrote: Click on any cell in the row and run: Sub RowMaker() Dim r As Range, n As Long, nxtrow As Long, r2 As Range Set r = ActiveCell.EntireRow nxtrow = r.Row + 1 n = Application.InputBox(prompt:="How many rows", Type:=1) Set r2 = Range("A" & nxtrow & ":A" & nxtrow + n - 1) r.Copy r2 End Sub -- Gary''s Student - gsnu200860 "teo410" wrote: In my spreadsheet, I was wondering if I could set a macro to copy an entire row, ask me how many copies of the line I would like to make, and paste them underneath the original line. Any help would be greatly appriciated! |
All times are GMT +1. The time now is 04:32 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com