PDA

View Full Version : Solved: Inserting an undetermined number of rows?



infinity
10-12-2009, 05:04 PM
Hello everyone,

I am trying to insert rows at the top of one worksheet based on data that is on another worksheet. Example, if I have 150 records on one sheet I want to insert 150 rows at the top of the other sheet to move the data that is already there down and put the new data at the top. Any suggestions? I tried this, but it does not work (no surprise there)...


lastRow = range("B" & Rows.Count).End(xlUp).Row
Range("1:1").Insert Shift:=xldown range("1:1" & lastrow)


Thank you!

GTO
10-12-2009, 07:22 PM
Greetings infinity,

Try:

Option Explicit

Sub exa()
Dim lLastRow As Long

'// Change sheet names to suit.//
With ThisWorkbook
lLastRow = .Worksheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
.Worksheets("Sheet1").Rows("1:" & lLastRow).Copy
.Worksheets("Sheet3").ranage("A1").Insert xlDown
End With
Application.CutCopyMode = False
End Sub


Does that help?

Mark

infinity
10-12-2009, 07:42 PM
Worked perfect!!!!!! Thank you so much! :beerchug: