×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Autofill Method of Range Calss Failed

Autofill Method of Range Calss Failed

Autofill Method of Range Calss Failed

(OP)
I have the following code snippet, which causes the subject error:

Sheets("Nx=9.0g Fwd").Activate
Range(Cells(LastItemRow, 11), Cells(LastItemRow, 24)).Select
Selection.AutoFill Destination:=Range(Cells(LastItemRow + 1, 11), Cells(LastItemRow + 1, 24)), Type:=xlFillDefault

The odd part is I've lifted this code from another macro which works just fine:

Range(Cells(FirstAttachRow + i - 2, FirstAttachColumn), Cells(FirstAttachRow + i - 2, 100)).Select
Selection.AutoFill Destination:=Range(Cells(FirstAttachRow + i - 2, FirstAttachColumn), Cells(FirstAttachRow + i - 1, 100)), Type:=xlFillDefault

Suggestions?  Explanations of why this works in one place and not another would also be useful as I am a VBA novice.

Thanks,
-Turk

RE: Autofill Method of Range Calss Failed

(OP)
The following code worked:

Sheets("Nx=9.0g Fwd").Activate
Range(Cells(LastItemRow + 1, 11), Cells(LastItemRow + 1, 24)).FillDown

I'm still lost as to why the original code generated the error.

RE: Autofill Method of Range Calss Failed

The range and cell properties as you used them in the sample code rely on default expressions that return excel objects.  Occassionally the default object is not what you expect and the code doesn't work.  Try the following...

CODE

With Sheets("Nx=9.0g Fwd")
.Activate
.Range(.Cells(LastItemRow, 11), .Cells(LastItemRow, 24)).Select
Selection.AutoFill Destination:=.Range(.Cells(LastItemRow + 1, 11), .Cells(LastItemRow + 1, 24)), Type:=xlFillDefault
End With
The With statement lets you attach a property to a specific object explicitly using the dot operator. When you see .Range it is the same as Sheets("Nx=9.0g Fwd").Range

HTH

RE: Autofill Method of Range Calss Failed

(OP)
Didn't seem to solve the problem, but thanks for the info on the with command; quite handy!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources