I’m using a macro that writes data to a SQL Table everyday. Problem is that usually I have more than 300k rows to upload and Macro runs very slowly (more than 60 minutes). Is there anyway to speed up this process? Below part of the code, this is exactly where Macro spent most of time:
tb = "[Table_Test]"
Set Pos = ThisWorkbook.Sheets(“Sheet1”)
For i = 3 To last_row
query = "INSERT INTO " & tb & " ([DATE],[POSITION])"
query2 = " VALUES " & "('" & Format(CDate(Pos.Cells(i, 1)), "yyyy-mm-dd") & "'" & ", '" & Pos.Cells(i, 2) & "'" &");"
query = query & query2
Execute_SQL_218 (query)
query = False
Application.StatusBar = "Uploading Data To SQL..." & i
DoEvents
Next i
Application.StatusBarupdate andDoEventscould significantly trim the execution time already, but it wouldn't surprise me if bulk-inserting the records with anINSERT INTO... SELECTquery, i.e. querying your worksheet through ODBC rather than generating oneINSERTstatement per row, would bring the whole thing down to under a minute.query2is redundant, just use a_line continuation, no need to concatenatequery & query2