Sub PushAnalysisToSQL()
'Create a connection
Dim id, Name, Label, QCd, Category, Zone, Phase, Crest, GOC, WHC, OP, Gas, Oil, Water, RefWell, Display, LabelAnalysis, RetCap, FracGrad, User, Description As String
Dim row As Integer
Dim connection As New ADODB.connection
With Sheets("AnalysisToSQL")
'Connection to SQL server
connection.Open "Provider=SQLOLEDB;Data Source=SVG-SQL-003.dno.no;Initial Catalog=DNO_PVA;TRUSTED_CONNECTION=yes"
'Start in second row, because first row is headers
row = 2
'Run untill row is empty
Do Until IsEmpty(Cells(row, 1))
'Get data from column and dynamic row
id = .Cells(row, 1)
Name = .Cells(row, 2)
Label = .Cells(row, 3)
QCd = .Cells(row, 4)
Category = .Cells(row, 5)
Zone = .Cells(row, 6)
Phase = .Cells(row, 7)
Crest = .Cells(row, 8)
GOC = .Cells(row, 9)
HWC = .Cells(row, 10)
OP = .Cells(row, 11)
Gas = .Cells(row, 12)
Oil = .Cells(row, 13)
Water = .Cells(row, 14)
RefWell = .Cells(row, 15)
Display = .Cells(row, 16)
LabelAnalysis = .Cells(row, 17)
RetCap = .Cells(row, 18)
FracGrad = .Cells(row, 19)
User = .Cells(row, 20)
Description = .Cells(row, 21)
'Insert values into SQL Table
connection.Execute "insert into dbo.t_analysis (id, Name, Label, QCd, Category, Zone, Phase, Crest, GOC, WHC, OP, Gas, Oil, Water, RefWell, Display, LabelAnalysis, RetCap, FracGrad, User, Description) values ('" & id & "','" & Name & "','" & Label & "','" & QCd & "', '" & Category & "','" & Zone & "','" & Phase & "','" & Crest & "','" & GOC & "','" & HWC & "','" & OP & "','" & Gas & "','" & Oil & "','" & Water & "','" & RefWell & "','" & Display & "','" & LabelAnalysis & "','" & RetCap & "','" & FracGrad & "','" & User & "','" & Description & "')"
'Go to next row
row = row + 1
Loop
'Close and Clean the Connection
connection.Close
Set connection = Nothing
End With
End Sub
Bookmarks