Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Efficiency in code

Hello All

i have this code:

Public Sub refreshPivotTables()
Dim pt As PivotTable 'help
Dim Counter As Integer
Dim ptsDone As Integer
Dim PctDone As Single
Dim newHour As Integer
Dim newMinute As Integer
Dim newSecond As Integer
Dim waitTime As Long

'find the total amount of pivot tables
Counter = 0
For Each pt In ActiveWorkbook.Worksheets("Data Compilation").PivotTables
Counter = Counter + 1
ActiveWorkbook.Worksheets("PivotChartLog").Range(" A" & Counter) =
Counter
Next pt

'refresh each pivot table and show progress
ptsDone = 0
For Each pt In ActiveWorkbook.Worksheets("Data Compilation").PivotTables
' pt.PivotCache.MissingItemsLimit = xlMissingItemsNone

ActiveWorkbook.Worksheets("PivotChartLog").Range(" B" & ptsDone + 1)
= pt.Name & " Started Refresh"
ActiveWorkbook.Worksheets("PivotChartLog").Range(" C" & ptsDone + 1)
= Now()
' ActiveWorkbook.Save
pt.RefreshTable
ActiveWorkbook.Worksheets("PivotChartLog").Range(" D" & ptsDone + 1)
= pt.Name & " Refresh Done Sucessfully"
ActiveWorkbook.Worksheets("PivotChartLog").Range(" E" & ptsDone + 1)
= Now()
' ActiveWorkbook.Save
ptsDone = ptsDone + 1
PctDone = ptsDone / Counter
With frmUpdating
.lblWorkingOn.Caption = pt.Name
.FrameProgress.Caption = Format(PctDone, "0%")
.LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
End With
DoEvents

Next pt
'wait for msquery to finish
Application.OnTime Now() + TimeValue("00:00:03"), "UnloadfrmUpdating"
' Unload frmUpdating
ActiveWorkbook.Worksheets("Dashboard").Columns("E: E").EntireColumn.AutoFit

End Sub

and i am wondering do i need to have the DO EVENTS in there? what is it
doing? i understand that Do Events is like having a gap in the program
allowing for the OS to do other things. the question is, are there things
that the OS needs to do in my code? it is refreshing pivot tables and MS
query is involved, but i am still unsure if this is causing the loading of my
sheet to go slower.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Efficiency in code

Unless you have a DoEvents inside a loop then chances are
that pressing the Escape key or Ctrl + Break would be ignored.
Meaning that you or the user can't exit the program.
I doubt that DoEvents is causing any delay.

Turning off ScreenUpdating would probably speed things up.
However that could cause problems with the progress bar display.

--
Jim Cone
Portland, Oregon USA



"DawnTreader"
wrote in message
Hello All
i have this code:

Public Sub refreshPivotTables()
Dim pt As PivotTable 'help
Dim Counter As Integer
Dim ptsDone As Integer
Dim PctDone As Single
Dim newHour As Integer
Dim newMinute As Integer
Dim newSecond As Integer
Dim waitTime As Long

'find the total amount of pivot tables
Counter = 0
For Each pt In ActiveWorkbook.Worksheets("Data Compilation").PivotTables
Counter = Counter + 1
ActiveWorkbook.Worksheets("PivotChartLog").Range(" A" & Counter) =
Counter
Next pt

'refresh each pivot table and show progress
ptsDone = 0
For Each pt In ActiveWorkbook.Worksheets("Data Compilation").PivotTables
' pt.PivotCache.MissingItemsLimit = xlMissingItemsNone

ActiveWorkbook.Worksheets("PivotChartLog").Range(" B" & ptsDone + 1)
= pt.Name & " Started Refresh"
ActiveWorkbook.Worksheets("PivotChartLog").Range(" C" & ptsDone + 1)
= Now()
' ActiveWorkbook.Save
pt.RefreshTable
ActiveWorkbook.Worksheets("PivotChartLog").Range(" D" & ptsDone + 1)
= pt.Name & " Refresh Done Sucessfully"
ActiveWorkbook.Worksheets("PivotChartLog").Range(" E" & ptsDone + 1)
= Now()
' ActiveWorkbook.Save
ptsDone = ptsDone + 1
PctDone = ptsDone / Counter
With frmUpdating
.lblWorkingOn.Caption = pt.Name
.FrameProgress.Caption = Format(PctDone, "0%")
.LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
End With
DoEvents

Next pt
'wait for msquery to finish
Application.OnTime Now() + TimeValue("00:00:03"), "UnloadfrmUpdating"
' Unload frmUpdating
ActiveWorkbook.Worksheets("Dashboard").Columns("E: E").EntireColumn.AutoFit

End Sub

and i am wondering do i need to have the DO EVENTS in there? what is it
doing? i understand that Do Events is like having a gap in the program
allowing for the OS to do other things. the question is, are there things
that the OS needs to do in my code? it is refreshing pivot tables and MS
query is involved, but i am still unsure if this is causing the loading of my
sheet to go slower.
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
Efficiency of Code Help Jbm Excel Programming 4 July 30th 09 01:05 PM
efficiency Carlee Excel Programming 3 September 24th 07 09:14 AM
VBA Code Efficiency Question Johnny[_9_] Excel Programming 2 August 28th 05 09:59 AM
Efficiency in my code (a critique from the guru's) Wally Steadman[_4_] Excel Programming 1 December 30th 04 12:45 PM


All times are GMT +1. The time now is 12:47 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"