Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

copy previous row down 5 rows

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick - 10 Nov 2007 20:45 GMT
Dim Cnt As Integer
I'm try to insert 5 new rows, then copy the previous row down thru the next
5 rows. I'm have some problem in getting it to work. Need help.
Thanks
 
Range("A" & SheetEnd).Select
   Set CpyCel = EndCel.Offset(-1, 0)
   Cnt = 5
   Do Until Cnt = 0
      Selection.EntireRow.Insert
      Cnt = Cnt - 1
   Loop
   RowStr = "" & CpyCel.Row & ":" & CDec(CpyCel.Row)
   Selection.EntireRow.Copy
Matthew Pfluger - 10 Nov 2007 21:22 GMT
Rick,

If I understand what you are trying to do correctly, try this:

Cells(SheetEnd - 1, 1).EntireRow.Copy
Range(Cells(SheetEnd, 1), Cells(SheetEnd + 4, 1)).Insert Shift:=xlDown
Application.CutCopyMode = False

If the macro copies the wrong row or inserts in the wrong place, play with
the row part of the Cells(.... object.

HTH,
Matthew Pfluger

>    Dim Cnt As Integer
> I'm try to insert 5 new rows, then copy the previous row down thru the next
[quoted text clipped - 10 lines]
>     RowStr = "" & CpyCel.Row & ":" & CDec(CpyCel.Row)
>     Selection.EntireRow.Copy
Rick - 10 Nov 2007 22:14 GMT
Thanks it works ok, except for I want to copy only formula's, how do I alter
your suggestion.

>    Dim Cnt As Integer
> I'm try to insert 5 new rows, then copy the previous row down thru the next
[quoted text clipped - 10 lines]
>     RowStr = "" & CpyCel.Row & ":" & CDec(CpyCel.Row)
>     Selection.EntireRow.Copy
Rick - 11 Nov 2007 18:15 GMT
Sorry Gentlemen:
         The Code caused the vba sub routine to jump to the vba code of the
sheet I'm trying to do the insert & copy too.
        There is got to be a simple way of cleanning up my original code.
It was done by recording a macro by doing the steps manually.


> Thanks it works ok, except for I want to copy only formula's, how do I alter
> your suggestion.
[quoted text clipped - 13 lines]
> >     RowStr = "" & CpyCel.Row & ":" & CDec(CpyCel.Row)
> >     Selection.EntireRow.Copy
Rick - 10 Nov 2007 22:25 GMT
Mathew:
   Also the statement  
Range(Cells(SheetEnd, 1), Cells(SheetEnd + 4, 1)).Insert Shift:=xlDown
causes the code to jump out of the current module to the sheet number vba code

>    Dim Cnt As Integer
> I'm try to insert 5 new rows, then copy the previous row down thru the next
[quoted text clipped - 10 lines]
>     RowStr = "" & CpyCel.Row & ":" & CDec(CpyCel.Row)
>     Selection.EntireRow.Copy
JLGWhiz - 11 Nov 2007 02:38 GMT
Rick, see if you can work with this:

Sub rsz()
 Dim lstRw As Long
 lstRw = Cells(Rows.Count, 1).End(xlUp).Row
 For i = lstRw To 1 Step -1
   Cells(i, 1).EntireRow.Copy
   Range(Cells(i + 1, 1), Cells(i + 5, 1)).EntireRow.PasteSpecial
Paste:=xlPasteFormulas
     If Cells(i, 1).Row <> 1 Then
       Cells(i, 1).Resize(5, 4).EntireRow.Insert
     End If
 Next
 Application.CutCopyMode = False
End Sub

>    Dim Cnt As Integer
> I'm try to insert 5 new rows, then copy the previous row down thru the next
[quoted text clipped - 10 lines]
>     RowStr = "" & CpyCel.Row & ":" & CDec(CpyCel.Row)
>     Selection.EntireRow.Copy
JLGWhiz - 11 Nov 2007 02:39 GMT
Be careful of the word wrap on one of those lines.

>    Dim Cnt As Integer
> I'm try to insert 5 new rows, then copy the previous row down thru the next
[quoted text clipped - 10 lines]
>     RowStr = "" & CpyCel.Row & ":" & CDec(CpyCel.Row)
>     Selection.EntireRow.Copy
Gord Dibben - 11 Nov 2007 03:00 GMT
Rather than warning OP about word wrap why don't you add a continuation mark in
your original code?

Gord Dibben  MS Excel MVP

>Be careful of the word wrap on one of those lines.
>
[quoted text clipped - 12 lines]
>>     RowStr = "" & CpyCel.Row & ":" & CDec(CpyCel.Row)
>>     Selection.EntireRow.Copy
JLGWhiz - 11 Nov 2007 03:20 GMT
Cause I forgot to do it. :(

> Rather than warning OP about word wrap why don't you add a continuation mark in
> your original code?
[quoted text clipped - 17 lines]
> >>     RowStr = "" & CpyCel.Row & ":" & CDec(CpyCel.Row)
> >>     Selection.EntireRow.Copy
Rick - 21 Nov 2007 16:50 GMT
Gentlemen:
    After many tries and re-tries, here is the answer to the querry:
 
Dim Cnt As Integer
   On Error GoTo ErrInsRow
   Cnt = 5
   Do Until Cnt = 0
      Range("A" & SheetEnd).Select
      Selection.EntireRow.Insert
      ActiveCell.Offset(-1, 0).Activate
      ActiveCell.EntireRow.Copy
      ActiveCell.Offset(1, 0).Activate
      Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone,
SkipBlanks:= _
          False, Transpose:=False
      Application.CutCopyMode = False
      Cnt = Cnt - 1
   Loop

>    Dim Cnt As Integer
> I'm try to insert 5 new rows, then copy the previous row down thru the next
[quoted text clipped - 10 lines]
>     RowStr = "" & CpyCel.Row & ":" & CDec(CpyCel.Row)
>     Selection.EntireRow.Copy
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.