Slowness looping through Excel Rows while retrieving info from database

bravura

Board Regular
Joined
Jan 27, 2010
Messages
51
Need help with slowness.
what i need to do is compare a spreadsheet (audit) to information in a database. what i am doing is uploading information in each row to a database where primary information blnumber on spreadsheet = primary key, then uploads information matching column header to field name.

What it's doing is going line by line, looping from column A to last column while inserting info to access database. the more lines there are on the spreadsheet, the slower it runs. heres the column looping code. can it be better?

c = current column number
a = current row number
colheader(c) is spreadsheet header that matches up with database field name.


For c = 1 To lastCol Step 1
On Error GoTo ErrorNoField
entryvalue = Cells(a, c).Value2
If entryvalue <> "" Then
sSQL = "UPDATE tblA SET " & colheader(c) & "= '" & entryvalue & "' WHERE BL = '" & blnumber & "';"
militarydb.Execute (sSQL)
End If
Next c
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
take a look at the .match function in vba. I read somewhere it goes a lot faster for a large amount of data
 
Upvote 0

Forum statistics

Threads
1,221,899
Messages
6,162,686
Members
451,782
Latest member
LizN

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top