P Parth Thaker New Member Jul 30, 2020 #1 Hi, I am trying to add VBA for inserting formula in a range, but compile error is coming. Can someone please help on this. i have imported the macro in personal.xlsb file hence i am using macro free work book. Attachments 1.XLSX 77.8 KB · Views: 1 Module2.bas 383 bytes · Views: 1
Hi, I am trying to add VBA for inserting formula in a range, but compile error is coming. Can someone please help on this. i have imported the macro in personal.xlsb file hence i am using macro free work book.
Chihiro Excel Ninja Jul 30, 2020 #2 You need to escape double quote inside the formula string, by using ""string"". Code: Range("S2:S" & lastRow).Formula = "=IF(OR(L2=30003322,L2=30004056,L2=30009486,L2=30013917,B2=""CHP Hydra""),""CHP-MMD"",IF(OR(L2=30004254,L2=30007286,Q2=""ABS""),""ABS"",""CHP-Oprn""))"
You need to escape double quote inside the formula string, by using ""string"". Code: Range("S2:S" & lastRow).Formula = "=IF(OR(L2=30003322,L2=30004056,L2=30009486,L2=30013917,B2=""CHP Hydra""),""CHP-MMD"",IF(OR(L2=30004254,L2=30007286,Q2=""ABS""),""ABS"",""CHP-Oprn""))"
P Parth Thaker New Member Jul 31, 2020 #3 Chihiro said: You need to escape double quote inside the formula string, by using ""string"". Code: Range("S2:S" & lastRow).Formula = "=IF(OR(L2=30003322,L2=30004056,L2=30009486,L2=30013917,B2=""CHP Hydra""),""CHP-MMD"",IF(OR(L2=30004254,L2=30007286,Q2=""ABS""),""ABS"",""CHP-Oprn""))" Click to expand... Thank you very much sir. Your solution did the job.
Chihiro said: You need to escape double quote inside the formula string, by using ""string"". Code: Range("S2:S" & lastRow).Formula = "=IF(OR(L2=30003322,L2=30004056,L2=30009486,L2=30013917,B2=""CHP Hydra""),""CHP-MMD"",IF(OR(L2=30004254,L2=30007286,Q2=""ABS""),""ABS"",""CHP-Oprn""))" Click to expand... Thank you very much sir. Your solution did the job.