View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Long Excel Formula in VBA gives error

One way:

Range("J10").Formula = "=IF(OR('CBA Template'!$L$275=1," & _
"'CBA Template'!$L$279=1),""A"",IF(AND(OR(" & _
"'CBA Template'!$F$230=""<1"",'CBA Template'!$F$230=1)," & _
"'CBA Template'!$J$370,'CBA Template'!$F$2280)," & _
"""B"",IF(AND('CBA Template'!$F$2280," & _
"'CBA Template'!$J$370,'CBA Template'!$L$281=1)," & _
"""C"",IF(OR(AND('CBA Template'!$F$2280," & _
"'CBA Template'!$L$281=2),AND('CBA Template'!$F$2280," & _
"'CBA Template'!$J$37<0,'CBA Template'!$L$281=1))," & _
"""D"",""E""))))"

Note you need to double quotation marks inside a string, just as in XL.



In article .com,
"Steve Mackay" wrote:

Hi all...using Excel 2002. I am trying to record a macro to put this
formula in a cell, but get an error "unable to record" when I try to
record it:

=IF(OR('CBA Template'!$L$275=1,'CBA
Template'!$L$279=1),"A",IF(AND(OR('CBA Template'!$F$230="<1",'CBA
Template'!$F$230=1),'CBA Template'!$J$370,'CBA
Template'!$F$2280),"B",IF(AND('CBA Template'!$F$2280,'CBA
Template'!$J$370,'CBA Template'!$L$281=1),"C",IF(OR(AND('CBA
Template'!$F$2280,'CBA Template'!$L$281=2),AND('CBA
Template'!$F$2280,'CBA Template'!$J$37<0,'CBA
Template'!$L$281=1)),"D","E"))))

It is pretty long, but the gist of it is that if a certain set of
conditions is met, then the formula returns "A", if another set is met,
"B", etc through "E". The formula works properly, I am just not able
to record it, and I am not sure why. Any ideas?

Is there a way to hard code it without trying to record?

Thanks,
Steve Mackay