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, 2023 in Others by Kithuzzz
• 38,020 points
1,342 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, 2023 by narikkadan
• 63,720 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer

Highlighting Unique List of Words in Each Cell of a Selection of Cells - Excel VBA

In a Textbox it is a vbcrlf ...READ MORE

answered Jan 12, 2023 in Others by narikkadan
• 63,720 points
479 views
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, 2023 in Others by narikkadan
• 63,720 points
1,052 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,690 points
934 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
• 63,720 points
1,931 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
• 63,720 points
1,690 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
• 63,720 points
1,233 views
0 votes
1 answer

VBA code help - Add a line for each missing date with the start and end date defined in a cell

Try this: Sub FillDates() Dim ...READ MORE

answered Jan 24, 2023 in Others by narikkadan
• 63,720 points
915 views
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, 2023 in Others by narikkadan
• 63,720 points
2,640 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