title: Pulling multiple excel values for VBA SQL query and using IN
body: <p>I've a below VBA code and I want to read four values a, b, c, d from an excel column (A1:A4) so those can be part of my SQL query IN statement when I connect to database.
  I build up the <strong>sWHEREclause</strong> to create ('a','b','c','d') string that but the final SQL query <strong>SQLStr</strong> seems to have some error and my code fails.</p>
  <p>Can someone please help.</p>
  <p>Thank you so much in advance.</p>
  <pre><code>Sub ADOExcelSQLServer()
  
      Dim Cn As ADODB.Connection 'connection variable
      Dim Server_Name As String ' text type
      Dim Database_Name As String
      Dim User_ID As String
      Dim Password As String
      Dim SQLStr As String
      Dim rs As ADODB.Recordset ' Database connection variable
      Dim rRange As Range
      Dim rCell As Range
      Dim sWHEREclause As String
      Set rs = New ADODB.Recordset
      
       
      Server_Name = &quot;server name&quot; 
      Database_Name = &quot;Database name&quot; 
      
      
      Set rRange = Sheet1.Range(&quot;A1:A4&quot;)
  
      For Each rCell In rRange
          sWHEREclause = sWHEREclause &amp; &quot;'&quot; &amp; rCell &amp; &quot;',&quot;
      Next rCell
      
      
      'SQLStr = &quot;Select * from MASTER_QUERY mq where mq.ModelNum in ('a','b','c','d')&quot; 'commented line
      SQLStr = &quot;Select * from MASTER_QUERY mq where mq.ModelNum  IN (&quot; &amp; sWHEREclause &amp; &quot;)&quot;
        
  
      Set Cn = New ADODB.Connection 'set connection with databse
      Cn.Open &quot;Provider=SQLOLEDB;Data Source=&quot; &amp; Server_Name &amp; &quot;; Initial Catalog=&quot; &amp; Database_Name &amp; &quot;; Integrated Security=SSPI;&quot; 'connection parameter to the database
  
      rs.Open SQLStr, Cn, adOpenStatic
       ' Dump to spreadsheet
       
       
      With Worksheets(&quot;sheet1&quot;).Range(&quot;b2:z500&quot;) ' Enter your sheet name and range here
     ' Range(A1).Value = &quot;ID)&quot;
  
          .ClearContents ' clear content first in excel
          .CopyFromRecordset rs
      End With
       '            Tidy up
      rs.Close
      Set rs = Nothing
      Cn.Close
      Set Cn = Nothing
      
  End Sub
  </code></pre>