title: Select range of rows to delete in Excel 2007. Runtime error 1004?
body: <p>I'm trying to write a code that deletes all rows between the 3rd and last data row on a worksheet. I have some short lines of code that first looks for the last row containing data, returns that row number. Subtracts 1 from it. And selects the data range from 3rd row to the 2nd to last row and attempts to delete them. But I run into error every time I run this code. Any suggestions?</p>
  
  <pre><code>Sheets("Sheet1").Activate
  lastrow = (Sheet1.Range("A1").Offset(Sheet1.Rows.Count - 1, 0).End(xlUp).Row) - 1
  Range("3: lastrow").Select  'Error 1004: method range of object _global failed
  Selection.Delete Shift:=xlUp 
  </code></pre>