Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Need Loop Optimization Assistance

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Need Loop Optimization Assistance

Try using the CopyFromRecordSet method of the Range object.


Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Chris C" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Need Loop Optimization Assistance

That worked. Thanks.

"Charles Williams" wrote:

Try using the CopyFromRecordSet method of the Range object.


Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Chris C" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seo , Search Engine Optimizer , Seo Search engine Optimization , search engine optimization services, SEO Consulting Se0 Guy Excel Worksheet Functions 0 March 8th 07 04:08 AM
Seo , Search Engine Optimizer , Seo Search engine Optimization , search engine optimization services, SEO Consulting Se0 Guy Excel Discussion (Misc queries) 0 March 8th 07 04:08 AM
Seo , Search Engine Optimizer , Seo Search engine Optimization , search engine optimization services, SEO Consulting Se0 Guy Links and Linking in Excel 0 March 8th 07 04:08 AM
Lookup / Loop / Optimization Help Requested [email protected] Excel Programming 0 March 1st 07 07:52 PM
Loop removal or optimization -matt Excel Programming 6 July 13th 06 07:27 PM


All times are GMT +1. The time now is 06:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"