View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
STEVE BELL STEVE BELL is offline
external usenet poster
 
Posts: 19
Default Long Excel Formula in VBA gives error

Try putting something like this in your code:

Workbooks("MyBook").Sheets("MySheet").Range("A1"). 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""))))

If "MySheet" is the activesheet than you can use

Range("A1").Formula = "= ....."

Just remember to use double quotes ("" "") instead of single quotes (" ")
and be sure to use the line extender ( _ ) to get around wrapping text.

Than be careful of exceeding the 255 characters per cell.

--
rand451
"Steve Mackay" wrote in message
oups.com...
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