Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Slow code operation when refering to different sheets

Hi folks,

I have the following code which takes values from Worksheets 2 to 8,
and writes them to Worksheet 9. It works just fine, except that it
runs quite slowly, copying only about 2 rows a second. From
observation, the lines within the If Then statement is what is slowing
it all down, possibly because I am copying to and from different
sheets. Any clues as to how I can speed it up easily?

===========================================
Function CopyDataToFinalTab()

CurrentOutputRow = 2
For MyWorksheets = 2 To 8

x = 5
Do While (Worksheets(MyWorksheets).Range("J" & x).Value < "")
If Worksheets(MyWorksheets).Range("J" & x).Value = "y" Then
Application.StatusBar = "Worksheet:" &
Worksheets(MyWorksheets).Name & ", Row:" & x
Worksheets("DataFile").Range("A" & CurrentOutputRow).Value
= Worksheets("Control").Range("B7").Value
Worksheets("DataFile").Range("B" & CurrentOutputRow).Value
= Worksheets("Control").Range("B8").Value
Worksheets("DataFile").Range("C" & CurrentOutputRow).Value
= Worksheets(MyWorksheets).Range("A" & x).Value
Worksheets("DataFile").Range("D" & CurrentOutputRow).Value
= Worksheets(MyWorksheets).Range("B" & x).Value
Worksheets("DataFile").Range("E" & CurrentOutputRow).Value
= Worksheets(MyWorksheets).Range("B2").Value
Worksheets("DataFile").Range("F" & CurrentOutputRow).Value
= Worksheets(MyWorksheets).Range("I" & x).Value

CurrentOutputRow = CurrentOutputRow + 1
End If

x = x + 1
Loop
Application.StatusBar = "Complete."

Next

End Function
================================================== ====

Thanks very much folks!
---
DFM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Slow code operation when refering to different sheets

Hi
test if
application.screenupdating =false
at the beginning
and
application.screenupdating=true
at the end helps to speed up the processing

"Deep Frayed Morgues" wrote:

Hi folks,

I have the following code which takes values from Worksheets 2 to 8,
and writes them to Worksheet 9. It works just fine, except that it
runs quite slowly, copying only about 2 rows a second. From
observation, the lines within the If Then statement is what is slowing
it all down, possibly because I am copying to and from different
sheets. Any clues as to how I can speed it up easily?

===========================================
Function CopyDataToFinalTab()

CurrentOutputRow = 2
For MyWorksheets = 2 To 8

x = 5
Do While (Worksheets(MyWorksheets).Range("J" & x).Value < "")
If Worksheets(MyWorksheets).Range("J" & x).Value = "y" Then
Application.StatusBar = "Worksheet:" &
Worksheets(MyWorksheets).Name & ", Row:" & x
Worksheets("DataFile").Range("A" & CurrentOutputRow).Value
= Worksheets("Control").Range("B7").Value
Worksheets("DataFile").Range("B" & CurrentOutputRow).Value
= Worksheets("Control").Range("B8").Value
Worksheets("DataFile").Range("C" & CurrentOutputRow).Value
= Worksheets(MyWorksheets).Range("A" & x).Value
Worksheets("DataFile").Range("D" & CurrentOutputRow).Value
= Worksheets(MyWorksheets).Range("B" & x).Value
Worksheets("DataFile").Range("E" & CurrentOutputRow).Value
= Worksheets(MyWorksheets).Range("B2").Value
Worksheets("DataFile").Range("F" & CurrentOutputRow).Value
= Worksheets(MyWorksheets).Range("I" & x).Value

CurrentOutputRow = CurrentOutputRow + 1
End If

x = x + 1
Loop
Application.StatusBar = "Complete."

Next

End Function
================================================== ====

Thanks very much folks!
---
DFM

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Slow code operation when refering to different sheets

"Frank Kabel" wrote in message ...
Hi
test if
application.screenupdating =false
at the beginning
and
application.screenupdating=true
at the end helps to speed up the processing


Exactly what I had been looking for. Thanks!
---
DFM
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
QUERY & HELP: so slow executing VBA code... :S John Keith Excel Worksheet Functions 3 February 13th 06 03:47 PM
Slow Code Frank Kabel Excel Programming 1 July 23rd 04 09:28 AM
Slow operation Mark B. Lloyd Excel Programming 1 April 28th 04 10:12 PM
Is this slow code? Tom Excel Programming 4 March 3rd 04 11:18 PM
VBA code refering to columns by name SkipAtPNS Excel Programming 2 February 27th 04 11:32 PM


All times are GMT +1. The time now is 02:35 PM.

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"