• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Help on VBA code error

Parth Thaker

New Member
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
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""))"

Thank you very much sir. Your solution did the job.
 
Back
Top