![]() |
Autofill & On Error Resume Next
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 -- Thank you so much for your help! |
Autofill & On Error Resume Next
Before the fill:
If Lastrow < 3 then Exit Sub "Dandelo" wrote: 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 -- Thank you so much for your help! |
Autofill & On Error Resume Next
this works great! Thank you
-- Thank you so much for your help! "Bob Umlas, Excel MVP" wrote: Before the fill: If Lastrow < 3 then Exit Sub "Dandelo" wrote: 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 -- Thank you so much for your help! |
All times are GMT +1. The time now is 12:43 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com