Vba Autofill Entire Row

  • I'm very new to VBA, so please excuse my ignorance.


    I have recorded a Macro to AutoFill a row in my Excel spreadsheet. The VBA code is very simple and looks like this:


    Code
    Selection.AutoFill Destination:=Range("D8460:T8460"), Type:=xlFillDefault
        Range("D8460:T8460").Select


    I thought I would simply be able to click on another row and re-use the Macro, but this doesn't seem to work, as I get the following error message: AutoFill method of Range class failed.


    What do I need to change in my code, so that it will work in any row I choose?


    Thanks,
    dachsie25

  • Re: Vba Autofill Entire Row


    Code
    Selection.AutoFill Destination:=ActiveCell.Range("A1:Q1"), Type:= _
            xlFillDefault


    The references above to A1 and Q1 are simply place-holders. A1 would mean whatever cell you begin is the first, and Q1 would mean 16 columns over. So if it begins in column D, it would stop at column T.

  • Re: Vba Autofill Entire Row


    sorry dont know what i was up to before,


    Try this:


    Code
    Selection.AutoFill Destination:=Selection.Resize(2, Selection.Columns.Count), Type:=xlFillDefault
    Selection.Offset(1, 0).Select
  • Re: Vba Autofill Entire Row


    Thank you all so much for your quick replies.


    I have now got it to work perfectly and it's going to save me an incredible amount of time:)


    Thanks again,
    dachsie25

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!