A
aileen
I am copying some if statements with a macro into a workbook and when I have
the following code in the macro it works perfectly:
Range("H1").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-5]=""JAN"",""JAN"",IF(RC[-5]=""FEB"",""FEB"",IF(RC[-5]=""MAR"",""MAR"",IF(RC[-5]=""APR"",""APR"",IF(RC[-5]=""MAY"",""MAY"",IF(RC[-5]=""JUN"",""JUN"",IF(RC[-5]=""JUL"",""JUL"",IF(RC[-5]=""AUG"",""AUG"",IF(RC[-5]=""SEP"",""SEP"",IF(RC[-5]=""OCT"",""OCT"",IF(RC[-5]=""NOV"",""NOV"",IF(RC[-5]=""DEC"",""DEC""))))))))))))"
Range("I1").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-5]=8,2008,IF(RC[-5]=9,2009,IF(RC[-5]=10,2010,IF(RC[-5]=11,2011,IF(RC[-5]=12,2012,IF(RC[-5]=13,2013,IF(RC[-5]=14,2014,IF(RC[-5]=15,2015,IF(RC[-5]=16,2016,IF(RC[-5]=17,2017,IF(RC[-5]=18,2018,IF(RC[-5]=19,2019,IF(RC[-5]=20,2020)))))))))))))"
Range("K1").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-5]=""C"",RC[-10],0)"
Range("L1").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-6]=""P"",RC[-11],0)"
Range("L2").Select
But as soon as I add this IF statement I get a syntax error:
Range("G1").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-5]=""SPX"",""SPX"",IF(RC[-5]=""SXB"",""SPX"",IF(RC[-5]=""SPQ"",""SPX"",IF(RC[-5]=""SPT"",""SPX"",IF(RC[-5]=""SZP"",""SPX"",IF(RC[-5]=""SXY"",""SPX"",IF(RC[-5]=""SXZ"",""SPX"",IF(RC[-5]=""SXM"",""SPX"",IF(RC[-5]=""SPB"",""SPX"",IF(RC[-5]=""SVP"",""SPX"",IF(RC[-5]=""SZJ"",""SPX"",IF(RC[-5]=""SZV"",""SPX"",IF(RC[-5]=""SPL"",""SPX"",IF(RC[-5]=""SYZ"",""SPX"",IF(RC[-5]=""SXG"",""SPX"",IF(RC[-5]=""SZT"",""SPX"",IF(RC[-5]=""QSE"",""QSPX"",IF(RC[-5]=""SAQ"",""QSPX"",IF(RC[-5]=""SLQ"",""QSPX"",IF(RC[-5]=""SWV"",""SPY"",IF(RC[-5]=""SZC"",""SPY"",IF(RC[-5]=""SWG"",""SPY"",IF(RC[-5]=""SFB"",""SPY"",IF(RC[-5]=""SYH"",""SPY"",IF(RC[-5]=""SUE"",""SPY"",IF(RC[-5]=""FYS"",""SPY"",IF(RC[-5]=""FYN"",""SPY"",IF(RC[-5]=""YQA"",""SPY"",IF(RC[-5]=""YAZ"",""SPY"",IF(RC[-5]=""CYU"",""SPY"",IF(RC[-5]=""JCA"",""SPY"",IF(RC[-5]=""CYY"",""SPY"",IF(RC[-5]=""RDQ"",""QSPY"",IF(RC[-5]=""RQQ"",""QSPY"",IF(RC[-5]=""SPY"",""SPY"",IF(RC[-5]=""SZQ"",""QSPX"",IF(RC[-5]=""JXD"",""JXA"",IF(RC[-5]=""JXE"",""JXA"",IF(RC[-5]=""JXA"","
"JXA"",IF(RC[-5]=""JXB"",""JXA"",IF(RC[-5]=""SPZ"",""SPX"",IF(RC[-5]=""SKQ"",""QSPX"",IF(RC[-5]=""SQP"",""QSPX"",
IF(RC[-2]=""AM"",""SPC"",IF(RC[-2]=""S&P"",""SP"",IF(RC[-2]=""EMINI"",""ES"",IF(RC[-2]=""IMM"",""EV"",IF(RC[-2]=""0810"",""SPC"",IF(RC[-2]=""0811"",""SPC"",IF(RC[-2]=""0812"",""SPC"",IF(RC[-2]=""0901"",""SPC"",IF(RC[-2]=""0902"",""SPC"",IF(RC[-2]=""0903"",""SPC"",IF(RC[-2]=""0904"",""SPC"",IF(RC[-2]=""0905"",""SPC"")))))))))))))))))))))))))))))))))))))))))))))))))))))))"
Range("G2").Select
Range("G1:I1").Select
Selection.Copy
Range("G2:I400").Select
ActiveSheet.Paste
Please let me know what is wrong with the IF statment. This IF statement
works perfectly when I just copy it into a cell. It only doesn't work when I
run it from a macro. Thanks!
the following code in the macro it works perfectly:
Range("H1").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-5]=""JAN"",""JAN"",IF(RC[-5]=""FEB"",""FEB"",IF(RC[-5]=""MAR"",""MAR"",IF(RC[-5]=""APR"",""APR"",IF(RC[-5]=""MAY"",""MAY"",IF(RC[-5]=""JUN"",""JUN"",IF(RC[-5]=""JUL"",""JUL"",IF(RC[-5]=""AUG"",""AUG"",IF(RC[-5]=""SEP"",""SEP"",IF(RC[-5]=""OCT"",""OCT"",IF(RC[-5]=""NOV"",""NOV"",IF(RC[-5]=""DEC"",""DEC""))))))))))))"
Range("I1").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-5]=8,2008,IF(RC[-5]=9,2009,IF(RC[-5]=10,2010,IF(RC[-5]=11,2011,IF(RC[-5]=12,2012,IF(RC[-5]=13,2013,IF(RC[-5]=14,2014,IF(RC[-5]=15,2015,IF(RC[-5]=16,2016,IF(RC[-5]=17,2017,IF(RC[-5]=18,2018,IF(RC[-5]=19,2019,IF(RC[-5]=20,2020)))))))))))))"
Range("K1").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-5]=""C"",RC[-10],0)"
Range("L1").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-6]=""P"",RC[-11],0)"
Range("L2").Select
But as soon as I add this IF statement I get a syntax error:
Range("G1").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-5]=""SPX"",""SPX"",IF(RC[-5]=""SXB"",""SPX"",IF(RC[-5]=""SPQ"",""SPX"",IF(RC[-5]=""SPT"",""SPX"",IF(RC[-5]=""SZP"",""SPX"",IF(RC[-5]=""SXY"",""SPX"",IF(RC[-5]=""SXZ"",""SPX"",IF(RC[-5]=""SXM"",""SPX"",IF(RC[-5]=""SPB"",""SPX"",IF(RC[-5]=""SVP"",""SPX"",IF(RC[-5]=""SZJ"",""SPX"",IF(RC[-5]=""SZV"",""SPX"",IF(RC[-5]=""SPL"",""SPX"",IF(RC[-5]=""SYZ"",""SPX"",IF(RC[-5]=""SXG"",""SPX"",IF(RC[-5]=""SZT"",""SPX"",IF(RC[-5]=""QSE"",""QSPX"",IF(RC[-5]=""SAQ"",""QSPX"",IF(RC[-5]=""SLQ"",""QSPX"",IF(RC[-5]=""SWV"",""SPY"",IF(RC[-5]=""SZC"",""SPY"",IF(RC[-5]=""SWG"",""SPY"",IF(RC[-5]=""SFB"",""SPY"",IF(RC[-5]=""SYH"",""SPY"",IF(RC[-5]=""SUE"",""SPY"",IF(RC[-5]=""FYS"",""SPY"",IF(RC[-5]=""FYN"",""SPY"",IF(RC[-5]=""YQA"",""SPY"",IF(RC[-5]=""YAZ"",""SPY"",IF(RC[-5]=""CYU"",""SPY"",IF(RC[-5]=""JCA"",""SPY"",IF(RC[-5]=""CYY"",""SPY"",IF(RC[-5]=""RDQ"",""QSPY"",IF(RC[-5]=""RQQ"",""QSPY"",IF(RC[-5]=""SPY"",""SPY"",IF(RC[-5]=""SZQ"",""QSPX"",IF(RC[-5]=""JXD"",""JXA"",IF(RC[-5]=""JXE"",""JXA"",IF(RC[-5]=""JXA"","
"JXA"",IF(RC[-5]=""JXB"",""JXA"",IF(RC[-5]=""SPZ"",""SPX"",IF(RC[-5]=""SKQ"",""QSPX"",IF(RC[-5]=""SQP"",""QSPX"",
IF(RC[-2]=""AM"",""SPC"",IF(RC[-2]=""S&P"",""SP"",IF(RC[-2]=""EMINI"",""ES"",IF(RC[-2]=""IMM"",""EV"",IF(RC[-2]=""0810"",""SPC"",IF(RC[-2]=""0811"",""SPC"",IF(RC[-2]=""0812"",""SPC"",IF(RC[-2]=""0901"",""SPC"",IF(RC[-2]=""0902"",""SPC"",IF(RC[-2]=""0903"",""SPC"",IF(RC[-2]=""0904"",""SPC"",IF(RC[-2]=""0905"",""SPC"")))))))))))))))))))))))))))))))))))))))))))))))))))))))"
Range("G2").Select
Range("G1:I1").Select
Selection.Copy
Range("G2:I400").Select
ActiveSheet.Paste
Please let me know what is wrong with the IF statment. This IF statement
works perfectly when I just copy it into a cell. It only doesn't work when I
run it from a macro. Thanks!