S
StargateFanFromWork
Hello! I have this great macro provided to me by a kind poster over a year
ago. I've never been able to figure out how to make what is copied a range.
I believe the "Range("A" & j & "").Select copies the first cell of column A
of the row that the cursor is on, which is what was needed at the time.
Today's sheet has formulas and/or formatting in most of the cells in the
row, so just easier to copy the row in the print area. Is it possible to
specify a set of cells that are then copied before macro pastes to a new
row? I currently need a modified macro using this code that copies from
column A to K of the empty row in A2 the cursors lands on in the beginning,
to new location user specifies. Here is the existing code:
**************************************
Sub InsertROWS()
'
ActiveSheet.Unprotect 'place at the beginning of the code
Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
Dim i As Long
Dim j As Long
Dim k As Long
On Error GoTo dontdothat
Do
i = InputBox("How many rows do you want to insert?", "Insert Rows ",
1)
Loop Until i <> 0
Do
j = InputBox("At what Excel row number do you want to start the
insertion?", "Insert Rows", 10)
Loop Until j <> 0
k = j + i - 1
Range("" & j & ":" & k & "").Insert shift:=xlDown
j = j - 1
Range("A" & j & "").Select
Selection.AutoFill Destination:=Range("A" & j & ":A" & k & ""),
Type:=xlFillDefault
Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Protect ' place at end of code
Exit Sub
dontdothat:
ActiveSheet.Protect ' place at end of code
End Sub
**************************************
I hope the question is clear ... (?) Thanks for any help.
D
ago. I've never been able to figure out how to make what is copied a range.
I believe the "Range("A" & j & "").Select copies the first cell of column A
of the row that the cursor is on, which is what was needed at the time.
Today's sheet has formulas and/or formatting in most of the cells in the
row, so just easier to copy the row in the print area. Is it possible to
specify a set of cells that are then copied before macro pastes to a new
row? I currently need a modified macro using this code that copies from
column A to K of the empty row in A2 the cursors lands on in the beginning,
to new location user specifies. Here is the existing code:
**************************************
Sub InsertROWS()
'
ActiveSheet.Unprotect 'place at the beginning of the code
Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
Dim i As Long
Dim j As Long
Dim k As Long
On Error GoTo dontdothat
Do
i = InputBox("How many rows do you want to insert?", "Insert Rows ",
1)
Loop Until i <> 0
Do
j = InputBox("At what Excel row number do you want to start the
insertion?", "Insert Rows", 10)
Loop Until j <> 0
k = j + i - 1
Range("" & j & ":" & k & "").Insert shift:=xlDown
j = j - 1
Range("A" & j & "").Select
Selection.AutoFill Destination:=Range("A" & j & ":A" & k & ""),
Type:=xlFillDefault
Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Protect ' place at end of code
Exit Sub
dontdothat:
ActiveSheet.Protect ' place at end of code
End Sub
**************************************
I hope the question is clear ... (?) Thanks for any help.
