Autofill error

Hi,

Im getting an error on the last line of the attached code

".Range("AI2:AT2").Autofill Destination:=.Range("AI2:AT" & r), Type:=xlFillDefault"

It says

"Object Variable or with block variable not set"

Does anyone know why this error is occurring, i recently expanded fromula from AU to AT, but thats the only change

Thanks
Seamus

Sub Autofill()
  Dim r As Long

 

    With Sheets("T-2")
 
 r = .Range("A" & Rows.Count).End(xlUp).Row

Sheets("T-2").Select

Range("AI2").Select
ActiveCell.Formula = "=IF(E2>1000000,""Yes"",""No"")"
Range("AJ2").Select
ActiveCell.Formula = "=IF(AI2=""Yes"",Q2,"""")"
Range("AK2").Select
ActiveCell.Formula = "=IF(AI2=""Yes"",E2,"""")"
Range("AL2").Select
ActiveCell.Formula = "=I2"
Range("AM2").Select
ActiveCell.Formula = "=IF(ISERROR(O2-AF2),"""",(O2-AF2))"
Range("AN2").Select
ActiveCell.Formula = "=IF(AM2<=5,""0-5"",IF(AM2<=15,""6-15"",IF(AM2<=30,""16-30"",IF(AM2<=90,""31-90"",""91+""))))"
Range("AO2").Select
ActiveCell.Formula = "=IF(AI2=""No"","""",IF(AM2<=5,""0-5"",IF(AM2<=15,""6-15"",IF(AM2<=30,""16-30"",IF(AM2<=90,""31-90"",""91+"")))))"
Range("AP2").Select
ActiveCell.Formula = "=IF(AK2<>"""",1,0)"
Range("AQ2").Select
ActiveCell.Formula = "=IF(X2=O2,""Keep"",""Delete"")"




.Range("AI2:AQ2").Autofill Destination:=.Range("AI2:AQ" & r), Type:=xlFillDefault

End With

With Sheets("Raw Data")
   r = .Range("A" & Rows.Count).End(xlUp).Row
   Sheets("Raw Data").Select
Range("AI2").Select
ActiveCell.Formula = "=IF(E2>1000000,""Yes"",""No"")"
Range("AJ2").Select
ActiveCell.Formula = "=IF(AI2=""Yes"",Q2,"""")"
Range("AK2").Select
ActiveCell.Formula = "=IF(AI2=""Yes"",E2,"""")"
Range("AL2").Select
ActiveCell.Formula = "=I2"
Range("AM2").Select
ActiveCell.Formula = "=IF(ISERROR(O2-AF2),"""",(O2-AF2))"
Range("AN2").Select
ActiveCell.Formula = "=IF(AM2<=5,""0-5"",IF(AM2<=15,""6-15"",IF(AM2<=30,""16-30"",IF(AM2<=90,""31-90"",""91+""))))"
Range("AO2").Select
ActiveCell.Formula = "=IF(AI2=""No"","""",IF(AM2<=5,""0-5"",IF(AM2<=15,""6-15"",IF(AM2<=30,""16-30"",IF(AM2<=90,""31-90"",""91+"")))))"
Range("AP2").Select
ActiveCell.Formula = "=IF(AK2<>"""",1,0)"
Range("AQ2").Select
ActiveCell.Formula = "=IF(X2=O2,""Keep"",""Delete"")"
Range("AR2").Select
ActiveCell.Formula = "=VLOOKUP(RC[-34],'Mapping Table'!C[-43]:C[-37],7,0)"
Range("AS2").Select
ActiveCell.Formula = "=IF(P2<=30,""0-30"",""30+"")"
Range("AT2").Select
ActiveCell.Formula = "=RIGHT(C2,6)"
Range("AU2").Select
ActiveCell.Formula = "=IF(H3>30,"">30"",IF(H3>14,""15-30"",""0-14""))"
Range("AV2").Select
ActiveCell.Formula = "=LEFT(J2,3)"


.Range("AI2:AV2").Autofill Destination:=.Range("AI2:AV" & r), Type:=xlFillDefault

End With

Open in new window

Seamus2626Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Saqib Husain, SyedEngineerCommented:
What is the value of r at this point. It must be greater than 2
0
 
Seamus2626Author Commented:
Hey ssaqibh, theres 3450 lines in the worksheet and ColA at this point

Thanks
Seamus
0
 
Patrick MatthewsCommented:
Not just that: the start of the destination range must be >2.  I.e. There cannot be overlap between source range and destination range.
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Patrick MatthewsCommented:
Not just that: the start of the destination range must be >2.  I.e. There cannot be overlap between source range and destination range.
0
 
Saqib Husain, SyedEngineerCommented:
Patrick, this is contrary to what the help file says. Check out the example there.
0
 
Rory ArchibaldCommented:
I can't see that line in your code at all.
0
 
Seamus2626Author Commented:
An error in another sub, all good now

Thanks
Seamus
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.