View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Run time error '9'

Once you get the first error cleared up, you will have problems with your
autofill code. You must include the source range in the destination range.
This is tested and worked fine for me:

Sub ABC()
Dim lastrow As Long
lastrow = Worksheets("Sheet1").Cells( _
Rows.Count, "A").End(xlUp).Row
Range("G2").AutoFill _
Destination:=Range("G2:G" & lastrow)
Range("I2").AutoFill _
Destination:=Range("I2:I" & lastrow)
End Sub


since you used the same location to determine the lastrow and your code
doesn't change that, you don't need to do it twice.
--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote:

Generally subscript out of Range would refer to the argument to Worksheets.
This is the sheet name (tab name): "Sheet1". You would get that error if
you did not have a "Sheet1" in the currently active workbook.

--
Regards,
Tom Ogilvy


"BEEJAY" wrote:

The following gives this error, with "subscript out of range" message
When I select debug, it hi-lites the 3rd line.
As far as I can see, this process is a direct copy from elsewhere in this ng.
what am I missing?

' Copy formulas in G2 and I2 down thru to last used Row

Dim lastrow As Long
lastrow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Range("G2").AutoFill Destination:=Range("G3:G" & lastrow)

lastrow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Range("I2").AutoFill Destination:=Range("I3:I" & lastrow)

Thanks in advance.