PC Review


Reply
Thread Tools Rate Thread

copy previous row down 5 rows

 
 
=?Utf-8?B?Umljaw==?=
Guest
Posts: n/a
 
      10th Nov 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWF0dGhldyBQZmx1Z2Vy?=
Guest
Posts: n/a
 
      10th Nov 2007
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

"Rick" wrote:

> 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
>

 
Reply With Quote
 
=?Utf-8?B?Umljaw==?=
Guest
Posts: n/a
 
      10th Nov 2007
Thanks it works ok, except for I want to copy only formula's, how do I alter
your suggestion.

"Rick" wrote:

> 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
>

 
Reply With Quote
 
=?Utf-8?B?Umljaw==?=
Guest
Posts: n/a
 
      10th Nov 2007
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
"Rick" wrote:

> 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
>

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      11th Nov 2007
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

"Rick" wrote:

> 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
>

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      11th Nov 2007
Be careful of the word wrap on one of those lines.

"Rick" wrote:

> 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
>

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      11th Nov 2007
Rather than warning OP about word wrap why don't you add a continuation mark in
your original code?


Gord Dibben MS Excel MVP

On Sat, 10 Nov 2007 18:39:00 -0800, JLGWhiz <(E-Mail Removed)>
wrote:

>Be careful of the word wrap on one of those lines.
>
>"Rick" wrote:
>
>> 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
>>


 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      11th Nov 2007
Cause I forgot to do it.

"Gord Dibben" wrote:

> Rather than warning OP about word wrap why don't you add a continuation mark in
> your original code?
>
>
> Gord Dibben MS Excel MVP
>
> On Sat, 10 Nov 2007 18:39:00 -0800, JLGWhiz <(E-Mail Removed)>
> wrote:
>
> >Be careful of the word wrap on one of those lines.
> >
> >"Rick" wrote:
> >
> >> 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
> >>

>
>

 
Reply With Quote
 
=?Utf-8?B?Umljaw==?=
Guest
Posts: n/a
 
      11th Nov 2007
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.

"Rick" wrote:

> Thanks it works ok, except for I want to copy only formula's, how do I alter
> your suggestion.
>
> "Rick" wrote:
>
> > 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
> >

 
Reply With Quote
 
=?Utf-8?B?Umljaw==?=
Guest
Posts: n/a
 
      21st Nov 2007
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

"Rick" wrote:

> 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to copy previous row and insert two blank rows dd Microsoft Excel Programming 1 1st May 2007 01:26 AM
Macro to copy previous row and insert two blank rows dd Microsoft Excel Misc 1 30th Apr 2007 11:25 PM
Copy rows of data (eliminating blank rows) from fixed layout =?Utf-8?B?U3dlZXBlYQ==?= Microsoft Excel Misc 1 13th Mar 2007 11:05 PM
Count the rows if the previous rows value is same as the next row value Dhruva101 Microsoft Excel Discussion 3 3rd Aug 2006 06:58 PM
add rows with copy format of previous row =?Utf-8?B?aHNn?= Microsoft Excel Programming 2 4th Mar 2005 07:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:16 AM.