ClimoC
Well-known Member
- Joined
- Aug 21, 2009
- Messages
- 584
Hi guys
Anyone see a more memory-efficient way of running this code?
It's importing from Excel to Project resources.
The Loop goes through 800 excel rows, same for the 'For' which goes through 800 resources.
Despite having calculation set to manual and screenupdating off, this takes nearly 2 1/2 minutes to run
(nb: this is the engine of the macro everything else before it is just declarations and seeting arrays)
Any suggestions for speeding this up? I have noticed people always saying "I don't to use too many loops..." and I can see the illogic in looping within a loop... my brain just can't do it any differently because since excel has far more objects and properties, I never need more than one loop to do anything I want!
Cheers
C
Anyone see a more memory-efficient way of running this code?
It's importing from Excel to Project resources.
The Loop goes through 800 excel rows, same for the 'For' which goes through 800 resources.
Despite having calculation set to manual and screenupdating off, this takes nearly 2 1/2 minutes to run
(nb: this is the engine of the macro everything else before it is just declarations and seeting arrays)
Code:
Dim xrow As Long, y As Long
xrow = 2
Dim mailname As String, loginINIT As String, Dept As String, subDept As String, Phone As String, fmIDx As Integer
Do While xrow <= xlsheet.Range("A" & Rows.count).End(xlUp).row
If CleanStr(xlcel(xrow, activecol)) <> "inactive" Then
resofmidx = CleanStr(xlcel(xrow, fmidxcol))
y = 0
For Each r In myProject.resources
If r.Text28 Like resofmidx Then
mailname = CleanStr(xlcel(xrow, mailnamecol))
loginINIT = CleanStr(xlcel(xrow, loginINITcol))
Dept = CleanStr(xlcel(xrow, deptcol))
subDept = CleanStr(xlcel(xrow, subdeptcol))
Phone = CleanStr(xlcel(xrow, phonecol))
fmIDx = CleanStr(xlcel(xrow, fmidxcol))
r.initials = loginINIT
r.Text29 = subDept
r.group = Dept
r.Text30 = Phone
r.Text28 = fmIDx
y = 5
Else
y = y
End If
Next
If y < 5 Then
mailname = CleanStr(xlcel(xrow, mailnamecol))
loginINIT = CleanStr(xlcel(xrow, loginINITcol))
Dept = CleanStr(xlcel(xrow, deptcol))
subDept = CleanStr(xlcel(xrow, subdeptcol))
Phone = CleanStr(xlcel(xrow, phonecol))
fmIDx = CleanStr(xlcel(xrow, fmidxcol))
Set myUser = myProject.resources.Add(mailname)
myUser.initials = loginINIT
myUser.Text29 = subDept
myUser.group = Dept
myUser.Text30 = Phone
myUser.Text28 = fmIDx
resources.Add loginINIT, myUser
ResourceNames = myUser.name
Else
End If
Else
End If
xrow = xrow + 1
Loop
Any suggestions for speeding this up? I have noticed people always saying "I don't to use too many loops..." and I can see the illogic in looping within a loop... my brain just can't do it any differently because since excel has far more objects and properties, I never need more than one loop to do anything I want!
Cheers
C