"IF" Condition

  • Thread starter Thread starter shafali
  • Start date Start date
S

shafali

I want to add a long "IF" condition in a macro but its giving me error
"unable to record"

IF(OR(ISNUMBER(SEARCH("upg",U6)),AE6="SA04"),"U",IF(OR(AE6="SA01",AE6="SA02",AE6="SA03",AE6="SA06",AE6="RP04",
AE6="RP13",AE6="RP14",AE6="SA09",
AE6="SA11"),"Y",IF(OR(AE6="SP01",AE6="SP02",AE6="SP07",AE6="SA07",AE6="SA08"),"S",IF(OR(AE6="SP03",AE6="SP04",AE6="SP06",AE6="RP03",
AE6="RP07",AE6="RP08", AE6="SA10"),"W","N"))))

Is it possible to record this macro???
 
First of all, you can shorten this formula as follows.

=IF(OR(ISNUMBER(SEARCH("upg",U7)),AE7="SA04"),"U",IF(OR(AE6={"SA01","SA02","SA03","SA06","RP04","RP13","RP14","SA09","SA11"}),"Y",IF(OR(AE6={"SP01","SP02","SP07","SA07","SA08"}),"S",IF(OR(AE6={"SP03","SP04","SP06","RP03","RP07","RP08","SA10"}),"W","N"))))

As for your macro, you may need to manually code this. For example, if you
wanted this formula in B1, then it may look like this.

Range("B1").Value =
"=IF(OR(ISNUMBER(SEARCH(""upg"",U7)),AE6=""SA04""),""U"",IF(OR(AE6={""SA01"",""SA02"",""SA03"",""SA06"",""RP04"",""RP13"",""RP14"",""SA09"",""SA11""}),""Y"",IF(OR(AE6={""SP01"",""SP02"",""SP07"",""SA07"",""SA08""}),""S"",IF(OR(AE6={""SP03"",""SP04"",""SP06"",""RP03"",""RP07"",""RP08"",""SA10""}),""W"",""N""))))"

HTH,
Paul
 
Back
Top