As you're aware, it is the double quotes in your cells that are interfering
with your SQL. There are two ways to address this:
1) If you have double quotes, but never have single quotes in your cells,
then use single quotes as your delimiters rather than double quotes. I.e.
> cr = "'" & ws.Cells(x, 2).Value & "'"
2) But if you have both kinds, then you'll need to convert your quotes to
pairs of quotes.
Because it's easier to read, I always tend to use single quotes as the
delimiters, but you can do it with double quotes if you prefer. This little
test
Option Explicit
Private Sub CommandButton1_Click()
Dim WS As Worksheet: Set WS = ActiveSheet
Dim X As Integer
For X = 1 To 3
Dim CR As String
CR = """" & Replace(WS.Cells(X, 2).Value, """", """""") & """"
Cells(X, "D").Value = CR
CR = "'" & Replace(WS.Cells(X, 2).Value, "'", "''") & "'"
Cells(X, "E").Value = CR
Next X
End Sub
puts a double-quote delimited version in D and a single-quote delimited
version in E.
Starting with February '2008' - "Inventory"
I get "February '2008' - ""Inventory""" for doubles and 'February ''2008'' -
"Inventory"' for singles. (Note that these are hard to read in a mail
browser, and are best copied to a mono-space text editor for inspection.