Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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! |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
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! |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
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! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
On Error Resume Next problem | Excel Discussion (Misc queries) | |||
On Error Resume Next (when next statement is Do Loop ...) | Excel Discussion (Misc queries) | |||
resume.xlw | Excel Discussion (Misc queries) | |||
On error resume next problem | Excel Discussion (Misc queries) | |||
can I create a new resume? | Excel Discussion (Misc queries) |