Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 320
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
On Error Resume Next problem Jim May Excel Discussion (Misc queries) 14 November 2nd 07 12:27 PM
On Error Resume Next (when next statement is Do Loop ...) EagleOne Excel Discussion (Misc queries) 2 September 26th 06 03:26 PM
resume.xlw OZDOC Excel Discussion (Misc queries) 6 July 31st 06 01:24 PM
On error resume next problem freekrill Excel Discussion (Misc queries) 2 December 7th 05 12:51 AM
can I create a new resume? in need of help. Excel Discussion (Misc queries) 1 August 10th 05 11:18 PM


All times are GMT +1. The time now is 07:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"