VBA code for dragging down contents of a cell

0 votes

I created a macro that copies (drags down) the contents of a cell and repeats the action numerous times. I nevertheless receive the warning "AutoFill Method or Range Class failed." What might be the cause?

Sub DragDown()

    Range("A10").Select
    Selection.AutoFill Range(Selection.Offset(0, 0), 
    Selection.Offset(2, 0))

    k = 0
    Do Until ActiveCell.Value = "00215F107"
        ActiveCell.Offset(k + 7, 0).AutoFill Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(2, 0))
        k = k + 7
    Loop

End Sub
Jan 9 in Others by Kithuzzz
• 28,900 points
42 views

1 answer to this question.

0 votes

Change this

ActiveCell.Offset(k + 7, 0).AutoFill Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(2, 0))
  

To this

Selection.AutoFill Range(Selection.Offset(0, 0), Selection.Offset(k + 7, 0))
answered Jan 9 by narikkadan
• 53,520 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer

VBA code to select only a table. I am getting a Run-time error '1004'; Method 'Range' of object'_Global' failed

No copy/paste, just direct assignment use.Value Sub Final_Report() ...READ MORE

answered Jan 13 in Others by narikkadan
• 53,520 points
84 views
0 votes
1 answer
0 votes
0 answers

Convert Rows to Columns with values in Excel using custom format

1 I having a Excel sheet with 1 ...READ MORE

Feb 17, 2022 in Others by Edureka
• 13,630 points
177 views
0 votes
1 answer

Remove formulas from all worksheets in Excel using VBA

Try this : Option Explicit Sub test1() ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 53,520 points
295 views
0 votes
1 answer

Calculate monthly average from daily data without PivotTable

Assuming you have the months in column D enter ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 53,520 points
200 views
0 votes
1 answer

Automate compound annual growth rate (CAGR) calculation

The following PowerPivot DAX formulas worked for ...READ MORE

answered Oct 7, 2022 in Others by narikkadan
• 53,520 points
281 views
0 votes
1 answer
0 votes
1 answer

How to increment the Range of a For Each loop - Excel VBA

Your formula seems to sum 1 single ...READ MORE

answered Jan 7 in Others by narikkadan
• 53,520 points
82 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP