Run time error '1004': AutoFill method of Range class failed
Hi guys,
I am completely new to VBA and currently started an apprenticeship this week, a lot of it is to do with coding VBA and C#.Net. I have been looking at some coding which has an issue somewhere along the lines, I have been trying to figure this one out all day and just cant solve this.
[SIZE=14px]The reason for the code:[/SIZE]
Currently trying to make this code work for an excel sheet to populate a data set which can vary from having 1000 rows to 1 row. The issue arises when i run the code and any data that only has 1 row seems to get this message and doesn't continue successfully. However, if there are more than 1 row of data, the issue does not exist and it continues fine.
What am I missing here? Any help would be highly appreciated as I am a complete newbie to coding.
The bug seems to be highlighting this area of the code marked in red.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
With ActiveSheet
lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
End With
Range("I1").Formula = "= H1*100"
Range("I1").AutoFill Destination:=Range("I1:I" & lastrow)
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("H:H").Select
Selection.Delete Shift:=xlToLeft
Range("I8").Select
ActiveWindow.SmallScroll Down:=-12
With ActiveSheet
lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
End With
Range("I1").Formula = "= H1*2"
Range("I1").AutoFill Destination:=Range("I1:I" & lastrow)
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Display More
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have tried to add an IF statement to the "lastrow" condition which didnt work for me. I have a trust book called the Excel Macros for dummies but haven't been successful with that either.
Many thanks in advance for your help.