LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Macro takes a while to run - should I be concerned?

Hi All,

Thanks for the feedback so far.

Please see code below. I'm new to VBA so I'm sure there are
improvments to the code below. The code is taking a time input (time
window) and converting it to an amount of people available (put into a
table for reference). The code does now run faster, without the
changes you have mentioned so far as I removed it from a workbook
which was 22mb in size.

Sub OT_to_Availability_Grid(ByVal OTStartTime As String,
BookedStartTime As String)
'called from the Resource_OT routine (for each day of the week)

Dim DayStart, OTStart, MR1S, MR1E, OTEnd As Date
Dim DayStart_to_OTStart, OTStart_to_MR1S, MR1S_to_MR1E, MR1E_to_OTEnd,
OTStart_to_OTEnd As Date
Dim DayStart_to_OTStart_10m, OTStart_to_MR1S_10m, MR1S_to_MR1E_10m,
MR1E_to_OTEnd_10m, OTStart_to_OTEnd_10m As Integer

DayStart = 0.25

Dim Count, myOffset, TaskOffset, MROffset, StaffAmount As Integer
Dim Task As String

Dim c As Range
For Each c In Worksheets("Sched OT").Range(OTStartTime).Cells
If Not c.Value = "" Then ' Is the cell empty?
'c.Interior.ColorIndex = 3
'c.Offset(0, 1).Interior.ColorIndex = 3
'Else
OTStart = c.Value ' Get information required
OTEnd = c.Offset(0, 1).Value
MR1S = c.Offset(0, 2).Value
MR1E = c.Offset(0, 3).Value
Task = c.Offset(0, 4).Value

StaffAmount = 1
MROffset = 5

Select Case Task

Case Is = "Proc M"
TaskOffset = 0
Case Is = "Proc A"
TaskOffset = 1
Case Is = "MHE"
TaskOffset = 2
Case Is = "XD"
TaskOffset = 3
Case Is = "IND"
TaskOffset = 4

End Select

DayStart_to_OTStart = OTStart - DayStart 'Work out time between
duty elements
OTStart_to_MR1S = MR1S - OTStart 'Work out time between duty
elements
MR1S_to_MR1E = MR1E - MR1S 'Work out time between duty elements
MR1E_to_OTEnd = OTEnd - MR1E 'Work out time between duty elements
OTStart_to_OTEnd = OTEnd - OTStart 'used when there is no MR

DayStart_to_OTStart_10m = DayStart_to_OTStart / (1 / 144) 'Work
out 10 in blocks
OTStart_to_MR1S_10m = OTStart_to_MR1S / (1 / 144) 'Work out 10 in
blocks
MR1S_to_MR1E_10m = MR1S_to_MR1E / (1 / 144) 'Work out 10 in blocks
MR1E_to_OTEnd_10m = MR1E_to_OTEnd / (1 / 144) 'Work out 10 in
blocks
OTStart_to_OTEnd_10m = OTStart_to_OTEnd / (1 / 144) 'used when
there is no MR

'Round the 10min blocks to whole numbers

With Application.WorksheetFunction
DayStart_to_OTStart_10m = .Round(DayStart_to_OTStart_10m, 0)
OTStart_to_MR1S_10m = .Round(OTStart_to_MR1S_10m, 0)
MR1S_to_MR1E_10m = .Round(MR1S_to_MR1E_10m, 0)
MR1E_to_OTEnd_10m = .Round(MR1E_to_OTEnd_10m, 0)
OTStart_to_OTEnd_10m = .Round(OTStart_to_OTEnd_10m, 0)

End With

myOffset = 0
Count = 0

If Not MR1S = "" Then

Do 'Fill Duty start to MR1 start timeslots

Worksheets("OT & Ag
Resource").Range(BookedStartTime).Offset(DayStart_ to_OTStart_10m +
myOffset, TaskOffset).Value = _
Worksheets("OT & Ag
Resource").Range(BookedStartTime).Offset(DayStart_ to_OTStart_10m +
myOffset, TaskOffset).Value + StaffAmount
myOffset = myOffset + 1
Count = Count + 1
Loop While Count < OTStart_to_MR1S_10m

Count = 0
myOffset = 0

Do 'Fill MR1 start to MR1 end timeslots

Worksheets("OT & Ag
Resource").Range(BookedStartTime).Offset(DayStart_ to_OTStart_10m +
OTStart_to_MR1S_10m + myOffset, MROffset).Value = _
Worksheets("OT & Ag
Resource").Range(BookedStartTime).Offset(DayStart_ to_OTStart_10m +
OTStart_to_MR1S_10m + myOffset, MROffset).Value + StaffAmount
myOffset = myOffset + 1
Count = Count + 1
Loop While Count < MR1S_to_MR1E_10m

Count = 0
myOffset = 0

Do 'Fill MR1 end to OTEnd timeslots

Worksheets("OT & Ag
Resource").Range(BookedStartTime).Offset(DayStart_ to_OTStart_10m +
OTStart_to_MR1S_10m + MR1S_to_MR1E_10m + myOffset, TaskOffset).Value =
_
Worksheets("OT & Ag
Resource").Range(BookedStartTime).Offset(DayStart_ to_OTStart_10m +
OTStart_to_MR1S_10m + MR1S_to_MR1E_10m + myOffset, TaskOffset).Value +
StaffAmount
myOffset = myOffset + 1
Count = Count + 1
Loop While Count < MR1E_to_OTEnd_10m

Count = 0
myOffset = 0


Else


Do 'Fill Duty start to MR1 start timeslots

Worksheets("OT & Ag
Resource").Range(BookedStartTime).Offset(DayStart_ to_OTStart_10m +
myOffset, TaskOffset).Value = _
Worksheets("OT & Ag
Resource").Range(BookedStartTime).Offset(DayStart_ to_OTStart_10m +
myOffset, TaskOffset).Value + StaffAmount
myOffset = myOffset + 1
Count = Count + 1
Loop While Count < OTStart_to_OTEnd_10m
End If
End If
Next c

End Sub

 
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
Need help with a macro that takes information from another workboo ZBelden Excel Programming 2 February 8th 08 03:46 PM
Slow Macro...Takes at least 1 Hour to Run [email protected] Excel Programming 10 January 16th 08 04:53 PM
Rerunning Macro takes longer after each consecutive use....Why MikeZz Excel Programming 3 April 12th 07 02:07 PM
how do i add time to see how long my macro takes to run ernestgoh[_6_] Excel Programming 2 July 16th 06 11:05 AM
Counting how long a Macro takes to run Diane Alsing Excel Programming 2 February 7th 05 05:41 PM


All times are GMT +1. The time now is 04:01 PM.

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

About Us

"It's about Microsoft Excel"