Insert rows in Excel 2007

Zahhhaaaa

Board Regular
Joined
Jun 29, 2011
Messages
62
Hello, I have a problem, I know it's not a big problem but I don't get it :P

I'm using

Code:
Sub insertrow()
ActiveSheet.Unprotect Password:="1"
With Rows(6)
    .Copy
    .Insert 'the copy will be put in the newl;y created row
End With
Application.CutCopyMode = False
ActiveSheet.Protect Password:="1"
End Sub

to copy row 6 and insert a copy of it below.

My problem is that the new row appears ABOVE, not below where I wanted it. What's wrong with the code?

PS. Range a6:d6 is what needs to be copied. Is it possible to select only this range, not the whole row? (but this is not necessary)
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Here's one way:
Code:
Sub MyInsertRow()
 
    ActiveSheet.Unprotect Password:="1"
    Rows(7).EntireRow.Insert
    Range("A6:D6").Copy
    Range("A7").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveSheet.Protect Password:="1"
    
End Sub
 
Upvote 0
Joe4, just curious, is it possible that when I copy this row a6:d6 and it appears on a7, that when I copy row a6 again, it appears on a8, and so on ?? That every new row appears below previous copy?

Code works perfectly, but if it's possible to have this little thing added in code you gave, I would approciate it very much!
 
Upvote 0
If you can determine the logic for doing this, then yes.

Maybe you can place some sort of indicator in one of the unused columns that indicates that row was inserted, so when the code it runs, it will place it below all those values (i.e. place an "i" in column Z).

Or, if it is all being done within a single run of VBA code, you can add a loop counter to your code to keep track of how many rows you have added, and incorporate that into the insert code.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,253
Members
452,900
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top