Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofill method of Range Class Failed 1

Status
Not open for further replies.

lhrpa

Programmer
Apr 2, 2003
10
US
Help (again!)

I'm trying to autofill a column of data with a sequence number. I can find the range I need to fill no problem (thanks to the wonderful FAQ section :) ), but for some reason I'm getting an error on my autofill. Any suggestions?

Thanks a million!

Linda

Sub fillit()

Dim LastRow As Integer ' Find the last real row
LastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row

LastRow = LastRow - 11
'
Range("B16").FormulaR1C1 = "=+R[-1]C+1"
Selection.AutoFill _
Destination:=Range("B16:B" & LastRow), Type:=xlFillDefault
Range("B16:B" & LastRow).Select

End Sub
 
I think you need to select a range before you do the AutoFill line.

Instead of this code:
Code:
    Range("B16").FormulaR1C1 = "=+R[-1]C+1"
    Selection.AutoFill _
   Destination:=Range("B16:B" & LastRow), Type:=xlFillDefault
    Range("B16:B" & LastRow).Select

try this:
Code:
    Range("B16").Select
    Selection.FormulaR1C1 = "=+R[-1]C+1"
    Selection.AutoFill _
   Destination:=Range("B16:B" & LastRow), Type:=xlFillDefault
    Range("B16:B" & LastRow).Select


Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
That did the trick - thank you!!! You made my day!!

Linda
[sunshine]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top