+ Reply to Thread
Results 1 to 5 of 5

Autofill a destination range using last row value

Hybrid View

  1. #1
    Registered User
    Join Date
    01-25-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2007
    Posts
    5

    Autofill a destination range using last row value

    Hi i am trying to a part of my macro where the autofill function is used on one column.

    I have used the following line to find the last row in the spreadsheet:

    lastrow = Cells(Rows.Count, "A").End(xlup).Row + 1

    then i want to autofill the column J after i have put in the 1st value into cell J2

    Selection.AutoFill Destination:=Range("J2" & lastrow), Type:=xlFillDefault

    it comes up with Method range of object global failed

    Please help!

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Autofill a destination range using last row value

    jaym911,

    Try changing this section of code:

    Selection.AutoFill Destination:=Range("J2" & lastrow), Type:=xlFillDefault


    To this instead:
    Selection.AutoFill Destination:=Range("J2:J" & lastrow), Type:=xlFillDefault


    Hope this helps,
    ~tigeravatar

  3. #3
    Registered User
    Join Date
    11-29-2013
    Location
    Limerick, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Autofill a destination range using last row value

    Hi

    I'm very new to macros (comlete novice) and first time posting so forgive me in advance if my question has been asked already or if I am not making myself clear in what I'm asking. I'm trying to put 4 differenent formulas into 4 different columns and then use the autofill function to fill the formulas to the last row in each column on the sheet but when I run the macro it comes up with "Autofill method of Range class failed" - see what I've created below.

    I'd appreciate any help/direction you can give.

    Thanks

    Sub Formulas()
    '
    ' Formulas Macro
    lastrow = Cells(Rows.Count, "BE").End(xlUp).Row + 1
    Range("BE3") = "=IF(RC55="""",-30,IFERROR(RC55-R1C57,-30))"
    Selection.AutoFill Destination:=Range("BE3:BE" & lastrow), Type:=xlFillDefault

    lastrow = Cells(Rows.Count, "BE").End(xlUp).Row + 1
    Range("BF3") = "=IF(RC57="""",""no"",IF(AND(RC57>-30,RC57<1),""yes"",""no""))"
    Selection.AutoFill Destination:=Range("BF3:BF" & lastrow), Type:=xlFillDefault

    lastrow = Cells(Rows.Count, "BE").End(xlUp).Row + 1
    Range("BG3") = "=IF(RC58=""yes"",""FC Loaded"",""Check with SE""))"
    Selection.AutoFill Destination:=Range("BG3:BG" & lastrow), Type:=xlFillDefault

    lastrow = Cells(Rows.Count, "BE").End(xlUp).Row + 1
    Range("BH3") = "=RC1&""_""&RC2&""_""&RC3"
    Selection.AutoFill Destination:=Range("BH3:BH" & lastrow), Type:=xlFillDefault

    End Sub

  4. #4
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Autofill a destination range using last row value

    Sparky.

    Welcome to the forum.

    You have to start your own thread as per forum rules and in this new thread to add code tags around your codes as per forum rule#3
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  5. #5
    Registered User
    Join Date
    11-29-2013
    Location
    Limerick, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Autofill a destination range using last row value

    Thanks Fotis

    My apologies. I will get the hang of it soon!!

    Regards
    Sparky

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1