![]() |
Single line of code with line separator
Hello All -
I have an IF stmt that's fairly long, and it works. Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5, IF(OR(RC[-1]={""xx"",""xx""}),4.0, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3, IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2, IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" However, if I try to break it into segments for useability, I get an "Expected: end of statement" or "Syntax Error." Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5, _ IF(OR(RC[-1]={""xx"",""xx""}),4.0, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3, _ IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2, _ IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" The ONLY difference is the multiple lines. What is the magic to breaking up a line when I want more than 1 row? KarenF |
Single line of code with line separator
You would have to concatenate the breaks. Here is a an example for the first
break: Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5," & _ &"IF(OR(RC[-1]={""xx"",""xx""}),4.0," & _ "KarenF" wrote: Hello All - I have an IF stmt that's fairly long, and it works. Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5, IF(OR(RC[-1]={""xx"",""xx""}),4.0, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3, IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2, IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" However, if I try to break it into segments for useability, I get an "Expected: end of statement" or "Syntax Error." Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5, _ IF(OR(RC[-1]={""xx"",""xx""}),4.0, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3, _ IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2, _ IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" The ONLY difference is the multiple lines. What is the magic to breaking up a line when I want more than 1 row? KarenF |
Single line of code with line separator
Unfortunately, VBA sees the Formula all as one statement, so when you split a
single statement, You have to enclose the ending part in dbl quotes, insert a concatenate symbol then space and the attenuation mark, and reverese the process on the beginning of the next line. "KarenF" wrote: Hello All - I have an IF stmt that's fairly long, and it works. Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5, IF(OR(RC[-1]={""xx"",""xx""}),4.0, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3, IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2, IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" However, if I try to break it into segments for useability, I get an "Expected: end of statement" or "Syntax Error." Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5, _ IF(OR(RC[-1]={""xx"",""xx""}),4.0, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3, _ IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2, _ IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" The ONLY difference is the multiple lines. What is the magic to breaking up a line when I want more than 1 row? KarenF |
Single line of code with line separator
this will probably wrap, but just look for the _ and that's the end of each
line: ActiveCell.FormulaR1C1 = _ "IF(OR(RC[-1]={""xx"",""xx""}),4.0," & _ "IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5," & _ "IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3," & _ "IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5," & _ "IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2," & _ "IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" -- Gary "KarenF" wrote in message ... Hello All - I have an IF stmt that's fairly long, and it works. Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5, IF(OR(RC[-1]={""xx"",""xx""}),4.0, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3, IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2, IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" However, if I try to break it into segments for useability, I get an "Expected: end of statement" or "Syntax Error." Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5, _ IF(OR(RC[-1]={""xx"",""xx""}),4.0, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3, _ IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2, _ IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" The ONLY difference is the multiple lines. What is the magic to breaking up a line when I want more than 1 row? KarenF |
Single line of code with line separator
Everything after this...
ActiveCell.FormulaR1C1 = in your statement is a very long String value... you cannot do line continuations in the middle of a String. For example, if you had this line... FakeLongLine = "This is supposed to be a long line" you could NOT do this... FakeLongLine = "This is supposed _ to be a long line" which is what you did several times with your own long String value. Instead, to do a line continuation on my example above, you would have to form substrings, concatenate them and do the line continuation at the point of concatenation.... FakeLongLine = "This is supposed" & _ "to be a long line" Rick "KarenF" wrote in message ... Hello All - I have an IF stmt that's fairly long, and it works. Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5, IF(OR(RC[-1]={""xx"",""xx""}),4.0, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3, IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5, IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2, IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" However, if I try to break it into segments for useability, I get an "Expected: end of statement" or "Syntax Error." Range("P2").Select ActiveCell.FormulaR1C1 = "=IF(RC[-15]=""abc"",1.5, _ IF(OR(RC[-1]={""xx"",""xx""}),4.0, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx""}),3.5, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),3, _ IF(OR(RC[-1]={""A6"",""AB"",""AV"",""ZU"",""xx""}),2.5, _ IF(OR(RC[-1]={""xx"",""xx"",""xx"",""xx"",""xx"",""xx"",""xx"" ,""xx"",""xx""}),2, _ IF(OR(RC[-1]={""A1"",""A2"",""xx""}),1.5,"""")))))))" The ONLY difference is the multiple lines. What is the magic to breaking up a line when I want more than 1 row? KarenF |
All times are GMT +1. The time now is 07:48 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com