In VBA code, if you have a quote within a quoted string, you must repeat the quote twice.

 .Range("N24:N" & LastRow5).Value = "=IF(E.Data!S2="""","""",E.Data!S2&CHAR(10)) & IF(E.Data!Y2="""","""".........
etc.