Need Loop Optimization Assistance

C

Chris C

The code I have below steps through a VBA resultset inserting specific values
into a range of cells, one by one. Clearly, a repetitive single insertion is
slow; however, I'm not familiar enough with VBA to optimize a resultset based
query with something faster. Can anyone provide some additional help?

eventresults.MoveFirst
Dim i As Integer
i = 2
While Not eventresults.EOF
Sheets("Raw").Cells(i, 1) = eventresults.Fields(0).Value
Sheets("Raw").Cells(i, 2) = eventresults.Fields(1).Value
Sheets("Raw").Cells(i, 3) = eventresults.Fields(2).Value
Sheets("Raw").Cells(i, 4) = eventresults.Fields(3).Value
Sheets("Raw").Cells(i, 5) = eventresults.Fields(4).Value
Sheets("Raw").Cells(i, 6) = eventresults.Fields(5).Value
Sheets("Raw").Cells(i, 7) = (Sheets("Raw").Cells(i, 5) -
Sheets("Raw").Cells(i, 6))

i = i + 1
eventresults.MoveNext
Wend
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top