0
votes

I am receiving the following error message when trying to insert the below formula into the AS column.

Run-time error '1004': Method' "Range" of object'_Global' failed

Can someone please take a gander at my code and call out any mistakes? I'm driving myself crazy here.

 Sub Zero_Dollar_Opps()

 Dim LastRow As Long

 LastRow = Cells(Rows.Count, 2).End(xlUp).Row

'name last column $0 Opps
 Range("AS1").Value = "$0 Opps"

'insert formula for $0 Opps
 Range("AS2:AS" & LastRow).Formula = "=IF(AND(AP2=0,(OR(AL2=""1 - 
 Qualifying"", AL2=""2 - Validating"", AL2=""3 - Proposing"", AL2=""4 - 
 Negotiating""))),1,0)"

End Sub

Thank you Stackoverflow community!

2
is your formula really split up into multiple lines like above? - Scott Craner
No, all in one line. Sorry, should have clarified - Kcyr
When it stops what is the value of LastRow? I get no error with your code. - Scott Craner
Ran it today with identical code...no issues...weird - Kcyr

2 Answers

0
votes

Perhaps:

Sub Zero_Dollar_Opps()

 Dim LastRow As Long

 LastRow = Cells(Rows.Count, 2).End(xlUp).Row

'name last column $0 Opps
 Range("AS1").Value = "$0 Opps"

'insert formula for $0 Opps
 Range("AS2:AS" & LastRow).Formula = "=IF(AND(AP2=0,(OR(AL2=""1 - Qualifying"", AL2=""2 - Validating"", AL2=""3 - Proposing"", AL2=""4 -Negotiating""))),1,0)"

End Sub
0
votes

Resolved. Tried this morning w/ identical code and received no error messages. I knew there was a reason why I hated VBA..