:)Actually I got it figured out ...but thanks so much for responding.
I had to upload hundreds of cells vertically which was simple just a row at a time but this one caught me a little off guard but it works very well and is robust code.
This will upload a range of cells in a horizonal motif
Const ConnectionString As String = _
"Provider=SQLOLEDB.1;" & _
"Data Source=servername;" & _
"Initial Catalog=databasename;" & _
"User ID=username;" & _
"Password=userpassword;"
Dim Connection As ADODB.Connection
Set Connection = New ADODB.Connection
Connection.ConnectionString = ConnectionString
Dim SQLstr As String
Dim Recordset As Recordset
Dim rng0 As Range
Dim rng As Range
Dim r As Variant
Dim rngCol As Range
Dim wksExpense As Worksheet
Dim rngSR As Range
Dim rngUploaded As Range
Dim rngCO As Range
Set wksExpense = ThisWorkbook.Worksheets("Expense Forecast")
Set rngSR = wksExpense.Range("A3")
Set rngUploaded = wksExpense.Range("B3")
Set rngCO = wksExpense.Range("C3")
Set rng = wksExpense.Range("J1").Resize(2, 36)
Connection.Open
For Each rngCol In rng.Columns
SQLstr = "INSERT INTO tSrNew(SRNo, DateUpload, ChgOrderNo, EMONTH, EAMOUNT)" & _
" VALUES ('" & rngSR.Value & "', '" & rngUploaded.Value & "', '" & rngCO.Value & "', '" & rngCol.Cells(1).Value & "', " & rngCol.Cells(2).Value & ")"
'MsgBox SQLstr
Connection.Execute (SQLstr)
Next
If (Connection.State = ObjectStateEnum.adStateOpen) Then
Connection.Close
End If
|