+ Reply to Thread
Results 1 to 5 of 5

Excel VBA “Autofill Method of Range Class Failed”

  1. #1
    Forum Contributor
    Join Date
    06-08-2021
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    101

    Excel VBA “Autofill Method of Range Class Failed”

    Hello,

    I am using the following VBA code to refresh data in excel worksheets and fill the column A with formula and extend them to the last value row based on column B.

    so.Select
    so.Cells.ClearContents
    so.Range("B2").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False

    fcst.Select
    fcst.Cells.ClearContents
    fcst.Range("B2").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False

    so.Select
    so.Range("A1").Select
    ActiveCell.FormulaR1C1 = "Unique Key"
    so.Range("A2").Select
    ActiveCell.FormulaR1C1 = "=""SO""&COUNTIF(R2C3:RC[2],RC3)&""-""&RC3"
    Selection.AutoFill Destination:=Range("A2:A" & Range("B" & Rows.Count).End(xlUp).Row)
    Range(ActiveCell, ActiveCell.End(xlDown)).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    so.Columns("A:A").EntireColumn.AutoFit

    I get the error "Autofill Method of Range Class Failed" on the line Selection.AutoFill Destination:=Range("A2:A" & Range("B" & Rows.Count).End(xlUp).Row)

    Can anyone help me understand what I am doing wrong here. I am pretty new to VBA.

    Thanks

    VJ

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Excel VBA “Autofill Method of Range Class Failed”

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    06-08-2021
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    101

    Re: Excel VBA “Autofill Method of Range Class Failed”

    Thanks for the response AlphaFrog. I really appreciate it. When I used your code and it ran fine without throwing an error. But, Column A did not extend the formula from A2 all the way to the last value row. Any idea why that could be happening?

    VJ

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Excel VBA “Autofill Method of Range Class Failed”

    Is column B empty? You are using that column to determine the last used row of data.

    Try adding the sheet qualifier to the range for column B
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    06-08-2021
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    101

    Re: Excel VBA “Autofill Method of Range Class Failed”

    Yup, it works just fine now. Appreciate the help AlphaFrog. I will mark this post as SOLVED. Have a nice day!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] AutoFill method of Range class failed
    By guy123456 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-04-2017, 06:01 AM
  2. [SOLVED] Autofill Method of Range Class Failed help
    By nemo74 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-20-2013, 10:09 AM
  3. Autofill method of range class failed
    By cza38180 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2012, 06:29 AM
  4. autofill method of range class failed
    By savery101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2009, 11:24 AM
  5. Excel Autofill Method of Range Class Failed
    By Steve in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2006, 12:40 PM
  6. Excel Autofill Method of Range Class Failed
    By Steve in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2006, 11:20 AM
  7. [SOLVED] Autofill method of range class failed - sometimes
    By Intellihome in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-28-2005, 09:05 AM

Tags for this Thread

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