title: Insert Excel Cell values into an existing SQL table
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1792399/excel-vba-insert-into-statement-using-variables">Excel VBA INSERT INTO statement using variables</a>  </p>
  </blockquote>
  
  
  
  <p>I've just started learning a bit of VBA, I've managed to import data from a DB created in SQL Server just fine, now I'm trying to export data from Excel into the same DB.</p>
  
  <p>The following works just fine:</p>
  
  <pre><code>Dim cnState As ADODB.Connection
  Dim sSQL As String
  Set cnState = New Connection
  With cnState
  .Provider = "SQLOLEDB"
  .ConnectionString = "server=.\SQLEXPRESS; Trusted_Connection=Yes; database=SIM_PROJ"
  .Open
  End With
  sSQL = "Insert Into Alunos Values ('3', 'Tiago Aleixo', 'Rua dos Pincéis' , '1990-05-26' , 'M' , 'Multimédia' , 'D')"
  cnState.Execute sSQL
  
  End Sub
  
  Private Sub btn_goMenu_Click()
  
  Sheet1.Select
  </code></pre>
  
  <p>The only issue is, I've only managed to figure out how to insert actual values through the code, I want to be able to read a whole line in Excel and insert it into my DB.</p>
  
  <p>Something like this:</p>
  
  <pre><code>sSQL = "Insert Into Alunos Values (Range(A4).Value, Range(B4).Value, Range(C4).Value, Range(D4).Value, Range(E4).Value, Range(F4).Value, Range(G4).Value)"
  </code></pre>
  
  <p>IE, I only want values from line 4 to be inserted.</p>