VBA Autofill Error

Hobbes25

New Member
Joined
May 16, 2018
Messages
8
Good Afternoon guys

I have a macro that takes a file from a folder, formats it, and then locks and saves it. It pulls 4 different excel CSV files from one folder. The macro worked fine until I tried to implement the last two of the four. It is giving me run time error '1004' and saying "AutoFill method of Range class failed".

Range("E1").Select
ActiveCell.Formula = "AD Group"
If Range("A1").Value = "" Then
Else
Range("E2").Select
ActiveCell.Formula = "a-RRAxx-KYCHighRiskOffshoreRW"
Dim lastrowOffshoreRW As Long
lastrowOffshoreRW = Cells(Rows.Count, 1).End(xlUp).Row
Selection.AutoFill Destination:=Range("E2:E" & lastrowOffshoreRW)

The program seems to stop running whenever there is only one entry in the CSV file. If you add another entry it works fine. Any suggestions?

Thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi & welcome to MrExcel
try
Code:
lastrowOffshoreRW = Cells(Rows.Count, 1).End(xlUp).Row
[COLOR=#ff0000]If lastrowOffshoreRW > 1 Then [/COLOR]Selection.AutoFill Destination:=Range("E2:E" & lastrowOffshoreRW)
 
Upvote 0
thank you for the warm welcome fluff! unfortunately it is still throwing an error for me. is there anyway I could put in a blank line? whenever there are enough entries it runs and compiles fine. It gets past the spreadsheet with data from A1-A3, but the one that only has data from A1-A2 does not work
 
Upvote 0
Apologies, I didn't read the code properly, It should be
Code:
If lastrowOffshoreRW >[COLOR=#ff0000] 2[/COLOR] Then
 
Upvote 0
Fluff, wouldn't it have to be greater than 2 since he's starting in E2? Just a question...I'm learning from this also. :)

EDIT: Posting at the same time...I see you answered my question above. :cool:
 
Last edited:
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top