gsgriffin
Technical User
- Oct 17, 2002
- 27
It's been a long time since I've been in VBA. Working on a page that creates SQL code for me. Because of that, I would like to have the cells with field values I'm inputting automatically add backslashes before single quotes.
I've worked on some code that does a simple replace of ' with \', but Excel keep adding backslashes (I assume because after it finds and replaces the single quote, it looks to the next character and finds a single quote again (because the insert of the backslash moved the character.
I would like to have a onchange function that looks at the cell value (which is text) and changes text like:
"This isn't what I want"
to:
"This isn\'t what I want"
Editing a line and having change should not add a second backslash. Only one backslash. If one exists, don't add.
Any ideas on an elegant way to do this as opposed to taking the string, going through it character by character and inserting manually. Couldn't find anything anywhere, but I could be searching the wrong terms.
I've worked on some code that does a simple replace of ' with \', but Excel keep adding backslashes (I assume because after it finds and replaces the single quote, it looks to the next character and finds a single quote again (because the insert of the backslash moved the character.
I would like to have a onchange function that looks at the cell value (which is text) and changes text like:
"This isn't what I want"
to:
"This isn\'t what I want"
Editing a line and having change should not add a second backslash. Only one backslash. If one exists, don't add.
Any ideas on an elegant way to do this as opposed to taking the string, going through it character by character and inserting manually. Couldn't find anything anywhere, but I could be searching the wrong terms.