WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Fastest Way to Copy Data To Excel


Question:

I've got a routine which fills an Excel-sheet with data from a recordset. It does that cell by cell but it is very slow. The routine looks like:
While ! RS.eof
oCell1 = oWS1.Range("A%Counter%")
oCell1.Select
oCell1.Value = rs.fields("portnr")
oCell1 = oWS1.Range("B%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Relatie")
oCell1 = oWS1.Range("C%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Benchmark")
oCell1 = oWS1.Range("D%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Mabelcode")
oCell1 = oWS1.Range("E%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Fonds")
oCell1 = oWS1.Range("F%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Aantal")
oCell1 = oWS1.Range("G%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Val_OV")
oCell1 = oWS1.Range("H%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Koers_OV")
oCell1 = oWS1.Range("I%Counter%")
oCell1.Select
oCell1.Value = rs.fields("MW_OV")
oCell1 = oWS1.Range("J%Counter%")
oCell1.Select
oCell1.Value = rs.fields("GKP_OV")
oCell1 = oWS1.Range("K%Counter%")
oCell1.Select
oCell1.Value = rs.fields("KP_OV")
oCell1 = oWS1.Range("L%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Perc_OV")
oCell1 = oWS1.Range("M%Counter%")
oCell1.Select
oCell1.Value = rs.fields("MW_CV")
oCell1 = oWS1.Range("N%Counter%")
oCell1.Select
oCell1.Value = rs.fields("KP_CV")
oCell1 = oWS1.Range("O%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Res_CV")
oCell1 = oWS1.Range("P%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Perc_CV")
oCell1 = oWS1.Range("Q%Counter%")
oCell1.Select
oCell1.Value = rs.fields("PercMW_CV")
oCell1 = oWS1.Range("R%Counter%")
oCell1.Select
oCell1.Value = rs.fields("OR_CV")
oCell1 = oWS1.Range("S%Counter%")
oCell1.Select
oCell1.Value = rs.fields("Dep")
Counter = Counter + 1
rs.MoveNext
EndWhile
Is there a way to speed-up things, maybe inserting a whole row instead of cell for cell?

Answer:

You should be able to comment all the .select statements without hurting your script. see if that's any faster.

Depends on where the data is coming from. If you have the data in MS Access (or another database) you can use excel's .CopyFromRecordset to put in the data in one shot. .CopyFromRecordset works both for MS Access's basic and with ADO. Otherwise, you might try putting the data into a CSV file and importing it into excel via OLE.


Article ID:   W16618
File Created: 2005:02:18:12:21:38
Last Updated: 2005:02:18:12:21:38