PDA

View Full Version : How to deal with quotes within a string



Dabo
06-02-2009, 06:40 AM
Hi all,

I am struggling with this one :

In order to use a filter, I need to fill a cell with the value of another cell set at the right format

Ex:
Cell 1 = test
Cell 2 = ="=Test"

My code is roughly



cell2.value = "=" & """=" & cell1.value & """"



everything is okay, except when there are quotes within Cell1

Ex:
Cell 1 = test " test " test
=> Bug

How to cope with that ?

Simon Lloyd
06-02-2009, 08:13 AM
I don't understand what you mean, instead of adding lots of " toencapsulate quotes why not use something like:
cell2.value = "=" & Chr(34) & "=" & Chr(34) & cell1.value & """"
its not excatly what you want but saves confusion.

to see what other codes can be used in VBA you can look here (http://www.thecodecage.com/forumz/general-news-updates/96329-complete-ascii-table-use-visual-basic-applications.html)