Works first time condition is met, but none after that works

ClimoC

Well-known Member
Joined
Aug 21, 2009
Messages
584
Somezing iz veh-ree ztrange...

Ignore the fact that this code might look foreign... it's because it's Project.

The problem is that everything in the loop works fine for the first time it needs to do the larger half of the code, but for all the rest, the values don't get pulled through from excel.

I believe I've got some variables being set in the wrong places.

Can anyone see anything fundamentally flawed in the structure of the loop?

Cheers
C

Code:
Dim Start As String, actualDays As String, DurationDays As String, bidDays As String
 Dim jobStatus As String
 Dim jobDuration As Double
Dim xrow As Long, y As Long
    xrow = 2
    
    Do While xrow <= xlsheet.Range("A" & rows.Count).End(xlup).row

        Dim shotName As String, jobType As String, seqName As String
        
        shotName = xlcel(xrow, shotnamecol)
        jobType = xlcel(xrow, jobtypecol)
                
        Dim fmUniqueID As String, fmFMXID As String
        fmFMXID = xlcel(xrow, fmidxcol)
        fmUniqueID = xlcel(xrow, uidcol)
        
        Dim shotTask As Task
        Set shotTask = Nothing
        On Error Resume Next
        Set shotTask = ActiveProject.Tasks(shotName)
        On Error GoTo 0
        Err.Clear
        
        Dim TopTask As Task
        Dim parentTask As Task
        Dim seqTask As Task
        
        
        If Not shotTask Is Nothing Then
             If fmUniqueID <> "" Then
  
                For Each t In shotTask.OutlineChildren
                    If t.UniqueID Like fmUniqueID Then
                    On Error Resume Next
                        t.Text5 = xlcel(xrow, jobstatuscol)
                        t.Text7 = xlcel(xrow, jobNcol)
                        t.Text15 = Left(xlcel(xrow, coordncol), 254)
                        t.Text12 = xlcel(xrow, sequtypecol)
                        t.Text13 = xlcel(xrow, scenecol)
                        t.Duration7 = xlcel(xrow, actualdayscol)
                        t.Text2 = xlcel(xrow, recordcol)
                        t.Duration2 = xlcel(xrow, bidtimecol)
                        t.Text6 = xlcel(xrow, turnovercol)
                        t.Start1 = xlcel(xrow, startcol)
                        t.Finish1 = xlcel(xrow, finishcol)
                        t.Text11 = xlcel(xrow, unitcol)
                        t.Date2 = xlcel(xrow, clientddcol)
                        t.Text9 = xlcel(xrow, statuscol)
                        Err.Clear
                   End If
                Next t
            ElseIf fmUniqueID = "" Then
                For Each tt In myProject.Tasks
                    If tt.Text2 Like fmFMXID Then
                        myProject.Tasks.Add Name:=jobType, Before:=tt.ID + 1
                        With myProject.Tasks(jobType)

                                    shotName = xlcel(xrow, shotnamecol)
                                    jobType = xlcel(xrow, jobtypecol)
                                    seqName = xlcel(xrow, seqnamecol)
                                    
                                   
                                    jobStatus = xlcel(xrow, jobstatuscol)
                            
                                    Dim userName As String
                                    userName = xlcel(xrow, usernamecol)

                                    Start = xlcel(xrow, startcol)
                                    actualDays = xlcel(xrow, actualdayscol)
                                    DurationDays = xlcel(xrow, durationdayscol)
                                    bidDays = xlcel(xrow, biddayscol)
                                    On Error Resume Next

                                    
                                        Set seqTask = sequences(seqName)
                            
                                                                      
                            

                                    
                                        Set shotTask = shots(shotName)
                                   Err.Clear
                              
                                    initials = xlcel(xrow, logincol)
                                    If resources.exists(initials) Then
                                        Set myUser = resources(initials)
                                    Else
                                        Set myUser = myProject.resources.Add(userName)
                                        myUser.initials = initials
                                        resources.Add initials, myUser
                                    End If
                            
                            
                                    
                            
                                    If Start = "" Then Start = Date
                                    If Start = "" Then
                                        jobDuration = 0
                                    ElseIf jobStatus = "complete" And actualDays <> "" Then
                                        jobDuration = Val(actualDays)
                                    ElseIf DurationDays <> "" Then
                                        jobDuration = Val(DurationDays)
                                    Else
                                        jobDuration = 0
                                    End If
                            
                                    
                                    .Start = CDate(Start)
                            
                                    On Error Resume Next
                                    .Duration = 480 * jobDuration
                                    On Error GoTo 0
                                    Err.Clear
                            
                                    .ResourceNames = myUser.Name
                                    .Text2 = xlcel(xrow, recordcol)
                                    
                                    On Error Resume Next
                                    .Text3 = xlcel(xrow, deptcol)
                                    On Error GoTo 0
                                    Err.Clear
                                    
                                    .Text4 = jobStatus
                                    .Text6 = xlcel(xrow, turnovercol)
                                    
                                    .Text7 = Left(xlcel(xrow, jobNcol), 254)
                                    
                                    .Text8 = xlcel(xrow, sequcol)
                                    .Text10 = shotName
                                    
                                    
                                    .Text20 = xlcel(xrow, statuscol)
                                    .Text12 = xlcel(xrow, sequtypecol)
                                    .Text13 = xlcel(xrow, scenecol)
                                           
                                    .Text14 = Left(xlcel(xrow, coordncol), 254)
                                    On Error Resume Next
                                    .Duration1 = xlcel(xrow, bidtimecol) & "d"
                                    On Error Resume Next
                                    .Duration3 = xlcel(xrow, padtimecol) & "d"
                                    On Error Resume Next
                                    .Duration5 = xlcel(xrow, extdelayTcol) & "d"
                                    On Error Resume Next
                                    .Duration6 = xlcel(xrow, remtimecol) & "d"
                                    On Error Resume Next
                                    .Duration7 = xlcel(xrow, actualdayscol) & "d"
                                    On Error Resume Next
                                    Err.Clear
                                    .Text1 = xlcel(xrow, jobcol)
                                    .Work = xlcel(xrow, workcol) & "d"
                                    
                                    .Duration = xlcel(xrow, workcol) & "d"
                                    .Text11 = xlcel(xrow, unitcol)
                                    .Date1 = xlcel(xrow, clientddcol)
                            
                                    .UniqueIDPredecessors = xlcel(xrow, uidprecol)
                                    .UniqueIDSuccessors = xlcel(xrow, uidsuccol)
                                    .Date1 = xlcel(xrow, clientddcol)
                            End With
                    Else

                    End If
              Next
        End If
       End If
        
            
                    
        
        xrow = xrow + 1
    Loop

NB : Const ref's are used in this, all the 'col' are just column integers, and they never change.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,216,050
Messages
6,128,498
Members
449,455
Latest member
jesski

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top