VBA - Resize Range to Fit Pasted Data

Sundae

New Member
Joined
Jul 25, 2011
Messages
44
Hello, I have the following code:

Sub Copy_Rows_RLB()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Dim nextrow As Long, i As Long<o:p></o:p>
<o:p></o:p>
Application.ScreenUpdating = False<o:p></o:p>
<o:p></o:p>
With Worksheets("Payroll")<o:p></o:p>
.Unprotect<o:p></o:p>
.Range("Top_5").Copy<o:p></o:p>
.Range("GrandTotals").Resize(1, 1).Insert Shift:=xlDown<o:p></o:p>
<o:p></o:p>
For i = 1 To WorksheetFunction.CountIf(Sheets("EEData").Columns("A"), Range("DEPT"))<o:p></o:p>
nextrow = .Cells(Rows.Count, "A").End(xlUp).Row<o:p></o:p>
Range("A" & nextrow + 1).PasteSpecial<o:p></o:p>
<o:p></o:p>
Next i

.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True<o:p></o:p>
<o:p> </o:p>
End With

*********

I am having an issue with the resizing range line, let's say that I am pasting the Range Top_5 10 times, well only 1 pasted range appears above the Range Grand Totals, then another 10 are pasted below the Range Grand Totals. Any assistance is appreciated.

Thanks!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,559
Messages
6,179,513
Members
452,921
Latest member
BBQKING

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