Link to home
Start Free TrialLog in
Avatar of erp1022
erp1022Flag for United States of America

asked on

error in vba code

Hello,

Could someone please tell me what is the problem with my vba code? When I try to debug it I keep getting that 'error 1004 application-defined or object-defined error'. I have tried different things with the syntax but I can't seem to find the issue. Thanks.



Sub Multiplier()

' Updates Multiplier column with '1' or '-1'
'
  Dim lastRow As Long
    lastRow = Range("A" & Rows.Count).End(xlUp).Row
    Range("E2").Formula = "=IF(OR(A2=41826,A2=50529,A2=50530,A2=51807,A2=51828,A2=51850,A2=51851,A2=51852,A2=51853,A2=51854,A2=51855,A2=51856,A2=51857,A2=51858,A2=51859,A2=51860,A2=51861,A2=51862,A2=51863,A2=51864,A2=51865,A2=51866,A2=51899,A2=E5184_I,A2=E5732_I) ""-1"", ""1"")"
    Range("E2").AutoFill Destination:=Range("E2:E" & lastRow), Type:=xlFillDefault

End Sub
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

I have highlighted the error producing parts in bold

    Range("E2").Formula = "=IF(OR(A2=41826,A2=50529,A2=50530,A2=51807,A2=51828,A2=51850,A2=51851,A2=51852,A2=51853,A2=51854,A2=51855,A2=51856,A2=51857,A2=51858,A2=51859,A2=51860,A2=51861,A2=51862,A2=51863,A2=51864,A2=51865,A2=51866,A2=51899,A2=E5184_I,A2=E5732_I),""-1"", ""1"")"
there are two "_I" s and one comma after the second _I
Second try with underlines
    Range("E2").Formula = "=IF(OR(A2=41826,A2=50529,A2=50530,A2=51807,A2=51828,A2=51850,A2=51851,A2=51852,A2=51853,A2=51854,A2=51855,A2=51856,A2=51857,A2=51858,A2=51859,A2=51860,A2=51861,A2=51862,A2=51863,A2=51864,A2=51865,A2=51866,A2=51899,A2=E5184_I,A2=E5732_I),""-1"", ""1"")"
SOLUTION
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try

=IF(OR(A2=41826,A2=50529,A2=50530,A2=51807,A2=51828,A2=51850,A2=51851,A2=51852,A2=51853,A2=51854,A2=51855,A2=51856,A2=51857,A2=51858,A2=51859,A2=51860,A2=51861,A2=51862,A2=51863,A2=51864,A2=51865,A2=51866,A2=51899,A2="E5184_I",A2="E5732_I"),"-1","1")
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial