Autofill & On Error Resume Next

D

Dandelo

I have a macro that uses Autofill to fill a formula down to the last row of
data. but when there is only 1 single row of data, this error message
appears:

Run-time error '1004'
Autofill Method of Range class failed

I know I need to add something to handle this error, but I can't seem to
find the right combination of Error handling syntax for the code in the
macro. The debug points to this piece of the macro:

Selection.AutoFill _
Destination:=Range("B2:B" & LastRow), Type:=xlFillDefault

Below is the code that is working unless there is only a single row of data.
Any help is greatly appreciated, thank you.

Dim LastRow As Long
'Remove the decimal fields from the amount
'Multiply Cell B2 by 100
Range("B2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-1]*100"

'Fill in the formula to the last row of data
'I got this code from Dave Peterson's 11/20/07 post from thread
"Autofill in macr"
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("B2").Select
Selection.AutoFill _
Destination:=Range("B2:B" & LastRow), Type:=xlFillDefault
End With
 
D

Dandelo

this works great! Thank you
--
Thank you so much for your help!


Bob Umlas said:
Before the fill:
If Lastrow < 3 then Exit Sub

Dandelo said:
I have a macro that uses Autofill to fill a formula down to the last row of
data. but when there is only 1 single row of data, this error message
appears:

Run-time error '1004'
Autofill Method of Range class failed

I know I need to add something to handle this error, but I can't seem to
find the right combination of Error handling syntax for the code in the
macro. The debug points to this piece of the macro:

Selection.AutoFill _
Destination:=Range("B2:B" & LastRow), Type:=xlFillDefault

Below is the code that is working unless there is only a single row of data.
Any help is greatly appreciated, thank you.

Dim LastRow As Long
'Remove the decimal fields from the amount
'Multiply Cell B2 by 100
Range("B2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-1]*100"

'Fill in the formula to the last row of data
'I got this code from Dave Peterson's 11/20/07 post from thread
"Autofill in macr"
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("B2").Select
Selection.AutoFill _
Destination:=Range("B2:B" & LastRow), Type:=xlFillDefault
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top