Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Error 1004 - Autofill


Hi,
I've got a macro like below:
lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("M2:X2").Select
Selection.AutoFill Destination:=Range("M2:X" & lngLastRow)

When I run the macro, I come up with error 1004 - Autofill method of range
class failed.

the lngLastRow is 2.

Can anyone help me?
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Error 1004 - Autofill


Hi

Your code is working perfectly, the issue is that lngLastRow is two, so
there are no rows to fill.

If you have some data in A3, and run the macro it will run with no error.

Hopes this helps.

Per

"diepvic" skrev i meddelelsen
...
Hi,
I've got a macro like below:
lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("M2:X2").Select
Selection.AutoFill Destination:=Range("M2:X" & lngLastRow)

When I run the macro, I come up with error 1004 - Autofill method of range
class failed.

the lngLastRow is 2.

Can anyone help me?
Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Error 1004 - Autofill

Thanks so much Per Jessen,

Do you have any idea to solve this? The data can have one row or more than
that. I can not predict it.

Should I use the If ...then...else statement?
like, If lngLastRow 2 then
Range("M2:X2").Select
Selection.AutoFill Destination:=Range("M2:X" & lngLastRow)

Thanks


-----------------------------------------------------------------------------
Less Spam Better enjoyable experience
Visit : news://spacesst.com
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Error 1004 - Autofill


Using a If ...Then statement like you suggest is the way to solve it, but
you don't need to select the range.

If lngLastRow 2 Then
Range("M2:X2").AutoFill Destination:=Range("M2:X" & lngLastRow)
End If

Regards,
Per

"diepvic" skrev i meddelelsen
...
Thanks so much Per Jessen,

Do you have any idea to solve this? The data can have one row or more than
that. I can not predict it.

Should I use the If ...then...else statement?
like, If lngLastRow 2 then
Range("M2:X2").Select
Selection.AutoFill Destination:=Range("M2:X" & lngLastRow)

Thanks


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
run time error 1004 general odbc error excel 2003 vba Mentos Excel Programming 5 January 24th 11 02:56 PM
Run-time error '1004': AutoFill method of Range class failed murkaboris Excel Discussion (Misc queries) 10 April 16th 09 09:06 PM
Run-time error '1004': AutoFill method of Range class failed murkaboris Excel Discussion (Misc queries) 3 April 14th 09 10:35 PM
Run-Time error 1004 in Autofill method of rangle class failed Bud Excel Programming 2 February 20th 09 03:32 PM
Error when cell A1 is not active and xlInsideVertical border formatthrowing error 1004 [email protected] Excel Programming 7 August 7th 08 08:43 PM


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

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

About Us

"It's about Microsoft Excel"