title: excel VBA to update existing record in SQL
body: <p>I currently have the below VBA to insert new records into my SQL Server from Excel. </p>
  
  <pre><code>Sub Button1_Click()
  
  Dim conn As New ADODB.Connection
  Dim iRowNo As Integer
  Dim sCustomerId, sFirstName, sLastName As String
  
  With Sheets("Sheet1")
  
      'Open a connection to SQL Server
      conn.Open "Provider=SQLOLEDB;Data Source=AUSWIDECUSTOMERS\SQL2012;Initial Catalog=Customers;Integrated Security=SSPI;"
  
      'Skip the header row
      iRowNo = 2
  
      'Loop until empty cell in CustomerId
      Do Until .Cells(iRowNo, 1) = ""
          sCustomerId = .Cells(iRowNo, 1)
          sFirstName = .Cells(iRowNo, 2)
          sLastName = .Cells(iRowNo, 3)
  
          'Generate and execute sql statement to import the excel rows to SQL Server table
          conn.Execute "insert into dbo.Customers (CustomerId, FirstName, LastName) values ('" &amp; sCustomerId &amp; "', '" &amp; sFirstName &amp; "', '" &amp; sLastName &amp; "')"
  
          iRowNo = iRowNo + 1
      Loop
  
      MsgBox "Customers imported."
  
      conn.Close
      Set conn = Nothing
  
  End With
  
  End Sub
  </code></pre>
  
  <p>What I am wanting to do is if anything changes with the sCustomerId record I inserted that I can come back in and update it. </p>
  
  <p>So for example</p>
  
  <p>current data set:</p>
  
  <pre><code>sCustomerId = 15 sFirstName = David SLastName = Smith 
  </code></pre>
  
  <p>So from excel I want it to be able type in <code>sCustomerID = 15</code> then update the record <code>SLastName = Warner</code></p>
  
  <p>Any ideas on how to make this change would be great. </p>