Microsoft Excel - How to write code for excel formula that have apostrophe and space ( " ") ?

Asked By Adik Manis on 04-Nov-13 01:51 AM

Hi there,

 I have some issue to write the code which is don't know how to write apostrophe and space in code.

The formula is like this. For example : =LEFT(B6,FIND(" ",B6))

So i write the code as below to make it flexible. But it turn error for the highlighted sentence below.
Sheet2.Cells(i, "F").Formula = "=Left(B" & i & ",Find(" & " "  " " & ", B" & i & "))"

Perhaps someone knows why it turn an error and can help me.

Thank you.
Harry Boughen replied to Adik Manis on 04-Nov-13 04:52 AM
Hello Adik,
Try something like this.

Sheet2.Cells(i, "F").Formula = "=Left(B" & i & ",Find(" & CHR(34) & "  "& CHR(34) & ", B" & i & "))"

Or
Sheet2.Cells(i, "F").Formula = "=Left(B" & i & ",Find(" & """ & "  " &""" & ", B" & i & "))"


Regards
Harry
Adik Manis replied to Harry Boughen on 05-Nov-13 09:21 PM
Hi Harry,

Thank you for the suggestion. I am using CHR(34) inside my code. It's work now! Thank you so much =))