SkyPadWindows code

Private Sub CheckBox1_Click()

End Sub

Private Sub a_Click()

End Sub

Private Sub ColumnY_Change()

End Sub

Private Sub ColumnZ_Change()

End Sub

Private Sub Frame1_Click()

End Sub

Private Sub Frame4_Click()

End Sub

Private Sub Gaussian_Click()

End Sub

Private Sub Label10_Click()

End Sub

Private Sub Label11_Click()

End Sub

Private Sub Label13_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub Label3_Click()

End Sub

Private Sub Label4_Click()

End Sub

Private Sub Label6_Click()

End Sub

Private Sub Label7_Click()

End Sub

Private Sub Label9_Click()

End Sub




Sub Userform_initialize()
With Listdistance
 .AddItem "    "
 .AddItem "nm"
 .AddItem "um"
 .AddItem "mm"
 .AddItem "cm"
 .AddItem "m"
 .AddItem "pixels"
End With
Listdistance.ListIndex = 2

With Listtime
 .AddItem "    "
 .AddItem "ms"
 .AddItem "s"
 .AddItem "min"
 .AddItem "h"
End With
Listtime.ListIndex = 3
End Sub

Private Sub TextBox1_Change()


TextBox1 = Listdistance.Value & " / " & Listtime.Value

End Sub
Private Sub nameBouton_OK_Click()


Dim Nbframe As Long
Dim First As Long
Dim countup As Long
Dim county As Long
Dim pause As Double
Dim Valeurmax As Long
Dim TF As Long
Dim Nbnuclei As Long
Dim nuclei As Long
Dim dir As Long
Dim prim As Long
Dim deuz As Long

Dim PctDone As Single

 
'ask you for parameters

Nbframe = Nbframes.Text
Valeurmax = Valeurmaxi.Text
TF = TFs.Text
pause = pauses.Text
Nbnuclei = Nbnucleis.Text
Xvalue = ColumnX.Text
Yvalue = ColumnY.Text
Tvalue = Column_plane.Text
ratio = Pixelsize.Text
Zvalue = ColumnZ.Text

'-------------------------------------------------
'prepare the worksheet
'-------------------------------------------------

Columns("aa:cc").Clear
Application.ScreenUpdating = False


Range(Cells(2, Xvalue), (Cells(Nbnuclei * Nbframe + 1, Xvalue))).Interior.Color = RGB(128, 128, 128)
Range(Cells(2, Yvalue), (Cells(Nbnuclei * Nbframe + 1, Yvalue))).Interior.Color = RGB(128, 128, 128)
If Thirddimension = True Then Range(Cells(2, Zvalue), (Cells(Nbnuclei * Nbframe + 1, Zvalue))).Interior.Color = RGB(128, 128, 128)
Range("r1", (Cells(Nbnuclei * Nbframe + 1, 24))).Interior.Color = RGB(255, 228, 225)
Range("ag2").Value = "Avg pauses duration"
Range("ah2").Value = "total time pausing"
Range("Ai2").Value = "% time in motion"
If Gaussian = True Then
Range("aj2").Value = "avg speed when moving"
Else
Range("aj2").Value = "median speed when moving"
End If
Range("ak2").Value = "nb of pauses"
Range("al2").Value = "total distance"
Range("r1").Value = "distances"
Range("s1").Value = "Speed"
Range("t1").Value = "thresholded speed"
Range("u1").Value = "coordinates 2nd threshold"
Range("u1:v1").Merge
Range("w1").Value = "coordinates 1nd threshold"
Range("w1:x1").Merge
Columns("r:am").AutoFit

Range("ao2").Value = "your parameters: "
Range("ao3").Value = "Conversion Factor: "
Range("Ao4").Value = "Number of frames: "
Range("ao5").Value = "Distance threshold (" & " " & Listdistance.Value & ") :"
Range("ao6").Value = "Time frame (" & " " & Listtime.Value & ") :"
Range("ao7").Value = "Speed threshold (" & Listdistance.Value & "/" & Listtime.Value & ") :"
Range("ao8").Value = "Number of particules: "
Range("ap3").Value = ratio
Range("ap4").Value = Nbframe
Range("ap5").Value = Valeurmax
Range("ap6").Value = TF
Range("ap7").Value = pause
Range("ap8").Value = Nbnuclei
If Thirddimension = True Then
Range("ap9").Value = "3D analysis"
Range("AO12").Value = "Z coordinates in column :"
Range("AP12").Value = Zvalue
Else
Range("ap9").Value = "2D analysis"
End If

Range("AO10").Value = "X coordinates in column :"
Range("AP10").Value = Xvalue
Range("AO11").Value = "Y coordinates in column :"
Range("AP11").Value = Yvalue
Range("AO13").Value = "Frames numbers in column :"
Range("AP13").Value = Tvalue
'---------------------------------
'Delete old graphs
'---------------------------------
     
    Dim I           As Integer
    Dim MsgBxTitle  As String
    Dim NumCharts   As Integer
    Dim Rtn         As VbMsgBoxResult
    Dim xlBook      As Workbook
    Dim xlSheet     As Worksheet
     
    If xlBookName = vbNullString Then xlBookName = ActiveWorkbook.Name
   Set xlBook = Workbooks(xlBookName)

    If xlSheetName = vbNullString Then xlSheetName = ActiveSheet.Name
    Set xlSheet = xlBook.Worksheets(xlSheetName)

    NumCharts = xlSheet.ChartObjects.Count
    
    For I = NumCharts To 1 Step -1
        xlSheet.ChartObjects(I).Delete
    Next I


compteur = 0

'---------------------------------------------
'Calculate for each particle
'---------------------------------------------

For nuclei = 1 To Nbnuclei
    Cells(nuclei + 2, "af").Value = "Particle" & nuclei
    countup = 0
    pausingt = 0
    county = 3
    Countd = 0
    First = (Nbframe * nuclei) - Nbframe + 1
    First2 = (Nbframe * nuclei) - Nbframe + 1
    dist = 0
    countb = 2
    nbpauses = 0
    'Columns("aa:An").Clear

    Cells((Nbframe * nuclei) - Nbframe + countb, "u").Value = Cells(ligne + 2, Xvalue).Value 'transfer first values of movement for tracking XY graph
    Cells((Nbframe * nuclei) - Nbframe + countb, "V").Value = Cells(ligne + 2, Yvalue).Value 'transfer first values of movement for tracking XY graph
    
    For ligne = (Nbframe * nuclei) - Nbframe + 1 To (Nbframe * nuclei) - 1
            If Thirddimension = False Then
             'calculate in 2D
            Cells(ligne + 2, "R").Value = (((Cells(ligne + 2, Xvalue).Value - Cells(First + 1, Xvalue).Value) ^ 2 _
             + (Cells(ligne + 2, Yvalue).Value - Cells(First + 1, Yvalue).Value) ^ 2) ^ (1 / 2)) * ratio
             Else
              'calculate in 3D
             Cells(ligne + 2, "R").Value = (((Cells(ligne + 2, Xvalue).Value - Cells(First + 1, Xvalue).Value) ^ 2 _
             + (Cells(ligne + 2, Yvalue).Value - Cells(First + 1, Yvalue).Value) ^ 2 + (Cells(ligne + 2, Zvalue).Value _
             - Cells(First + 1, Zvalue).Value) ^ 2) ^ (1 / 2)) * ratio
             End If
             Range("AB3").Value = 0
                If Cells(ligne + 2, "R").Value >= Valeurmax Then
                    Cells(ligne + 2, "R").Activate
                    ActiveCell.Interior.Color = vbRed
                    county = county + 1
                    ActiveCell.Copy Cells(county, "AA")
                    Cells(ligne + 2, Tvalue).Copy Cells(county, "AB")
                    Cells(ligne + 2, Tvalue).Interior.Color = vbRed
                    If county = 4 Then Cells(ligne + 2, "s").Value = (Cells(county, "AA").Value) / ((Cells(county, "AB").Value - 1) * TF) Else _
                    Cells(ligne + 2, "s").Value = (Cells(county, "AA").Value) / ((Cells(county, "AB").Value - Cells(county - 1, "AB").Value) * TF)
                    Cells(county, "ac").Value = Cells(ligne + 2, "s").Value
                    Cells((Nbframe * nuclei) - Nbframe + county - 1, "w").Value = Cells(ligne + 2, Xvalue).Value
                    Cells((Nbframe * nuclei) - Nbframe + county - 1, "x").Value = Cells(ligne + 2, Yvalue).Value

                    
                Else
                Cells(ligne + 2, "R").Clear
                Cells(ligne + 2, "r").Interior.Color = RGB(255, 228, 225)
                End If
                If Cells(county, "AC").Value >= pause Then
                    Cells(county, "AD").Value = Cells(county, "AC").Value
                    dist = Cells(ligne + 2, "r").Value + dist ' accumulates the distances made
            
            '------------------------------------------------------------------------------------
            'to show the speed over the second threshold and trace XY graph after second threshold
            '------------------------------------------------------------------------------------
                If Cells(ligne + 2, "s").Value >= pause Then
                    Cells(ligne + 2, "t").Value = Cells(ligne + 2, "s").Value
                    Cells(ligne + 2, "t").Interior.Color = vbGreen
                    countb = countb + 1
                    Cells(ligne + 2, "u").Value = Cells(ligne + 2, Xvalue).Value
                    Cells(ligne + 2, "V").Value = Cells(ligne + 2, Yvalue).Value
                Else
                    Cells(ligne + 2, "t").Clear
                    Cells(ligne + 2, "u").Clear
                    Cells(ligne + 2, "V").Clear
                    Cells(ligne + 2, "t").Interior.Color = RGB(255, 228, 225)
                    Cells(ligne + 2, "u").Interior.Color = RGB(255, 228, 225)
                    Cells(ligne + 2, "V").Interior.Color = RGB(255, 228, 225)
                End If
                    
                End If
                
                If Cells(ligne + 2, "R").Value >= Valeurmax Then First = ligne + 1
                
              
    compteur = compteur + 1
    PctDone = compteur / (Nbframe * Nbnuclei)
    UpdateProgressBar PctDone

    Next ligne
    Range("ac3").Value = pause


'------------------------------------
'calculates pausing parameters
'------------------------------------
    Cells(county + 1, "ab").Value = Nbframe
        For x = 4 To county
            If Cells(x, "AC").Value >= pause Then countup = countup + (Cells(x, "AB").Value - Cells(x - 1, "AB").Value) _
            Else pausingt = pausingt + (Cells(x, "AB").Value - Cells(x - 1, "AB").Value) * TF
            
            If Cells(x, "AC").Value < pause Then
                If Cells(x - 1, "ac").Value >= pause Then nbpauses = nbpauses + 1
            End If
   'calculate the duration of each pause
            If Cells(x, "AD").Value < pause Then Cells(x, "ae").Value = (Cells(x, "AB").Value - Cells(x - 1, "AB").Value) * TF + Cells(x - 1, "AE").Value
            If Cells(x, "AD").Value < pause Then Cells(x - 1, "ae").Clear
        Next x
        
        'if no speed at last frame, add it to pauses
        If Cells(county, "ab").Value < Nbframe Then
            pausingt = pausingt + (Cells(x, "AB").Value - Cells(x - 1, "AB").Value) * TF
            Cells(x, "ae").Value = (Cells(x, "AB").Value - Cells(x - 1, "AB").Value) * TF + Cells(x - 1, "AE").Value
            nbpauses = nbpauses + 1
           
        End If
            
        Cells(nuclei + 2, "AK").Value = nbpauses
        Cells(nuclei + 2, "ai").Value = (countup / Nbframe) * 100
        Cells(nuclei + 2, "Ah").Value = pausingt
        On Error Resume Next
        Cells(nuclei + 2, "AG").Value = Application.WorksheetFunction.Average(Range("ae4:ae500"))
        If countup > 0 Then
            If Gaussian = True Then
            Cells(nuclei + 2, "aj").Value = Application.WorksheetFunction.Average(Range("ad4:ad500"))
            Else
            Cells(nuclei + 2, "aj").Value = Application.WorksheetFunction.Median(Range("ad4:ad500"))
            End If
        End If
        
Cells(nuclei + 2, "al").Value = dist
           
'-----------------------------------
'Calculate persistence if option selected
'-----------------------------------

    If Persistence = True Then
         Range("am2").Value = "Persistence"
         If countup > 0.05 * Nbframe Then 'only calculate persistence when particle move at least 5% of the time
         If Thirddimension = True Then
         Cells(nuclei + 2, "am").Value = ((((Cells((Nbframe * nuclei) - Nbframe + county - 1, "w").Value - Cells((Nbframe * nuclei) - Nbframe + 2, Xvalue).Value) ^ 2 _
             + (Cells((Nbframe * nuclei) - Nbframe + county - 1, "x").Value - Cells((Nbframe * nuclei) - Nbframe + 2, Yvalue).Value) ^ 2 _
             + (Cells((Nbframe * nuclei) - Nbframe + county - 1, Zvalue).Value - Cells((Nbframe * nuclei) - Nbframe + 2, Zvalue).Value) ^ 2) ^ (1 / 2)) * ratio) _
             / Application.WorksheetFunction.Sum(Range("aa3", Cells(county, "aa")))
         Else
         Cells(nuclei + 2, "am").Value = ((((Cells((Nbframe * nuclei) - Nbframe + county - 1, "w").Value - Cells((Nbframe * nuclei) - Nbframe + 2, Xvalue).Value) ^ 2 _
             + (Cells((Nbframe * nuclei) - Nbframe + county - 1, "x").Value - Cells((Nbframe * nuclei) - Nbframe + 2, Yvalue).Value) ^ 2) ^ (1 / 2)) * ratio) _
             / Application.WorksheetFunction.Sum(Range("aa3", Cells(county, "aa")))
        End If
        End If
    End If

                '--------------------------------
                'Calculate MSD  and diffusion coefficient if asked
                '--------------------------------
                
                f = 0
                
                If MSD = True Then
                Range("an2") = "Diffusion coefficient"
                Cells(1, 43).Value = "Time interval"
                Cells(1, 43).Interior.Color = vbRed
                    For lign = (Nbframe * nuclei) - Nbframe + 1 To (Nbframe * nuclei) Step Nbframe
                        Cells(lign + 1, 43).Value = "Diffusion Coeff"
                        Cells(lign + 1, 43).Interior.Color = RGB(128, 128, 128)
                        Cells(lign + 2, 43).Value = "<MSD>"
                        Cells(lign + 2, 43).Interior.Color = vbBlue
                        Cells(lign + 2, 43).Font.Color = vbWhite
                        Next lign
                Columns("aa:Ae").Font.Color = vbWhite
                End If
                    
                If MSD = True Then
                    increment = 1
                    For colone = 44 To 44 + Nbframe - 2
                        Cells(1, colone).Value = increment * TF
                        Cells(1, colone).Interior.Color = vbRed
                        increment = increment + 1
                    Next colone
                    
                    If Thirddimension = False Then
                        For colone = 44 To 44 + Nbframe - 2
                            For lignes = (Nbframe * nuclei) - Nbframe + 2 To (Nbframe * nuclei) '- 1
                                Cells(lignes + 2, colone).Value = (((Cells(lignes + f + 1, Xvalue).Value - Cells(lignes, Xvalue).Value) ^ 2 _
                                + (Cells(lignes + f + 1, Yvalue).Value - Cells(lignes, Yvalue).Value) ^ 2)) * ratio
                                If lignes + f = (Nbframe * nuclei) Then Exit For
                            Next lignes
                            f = f + 1
                            Cells((Nbframe * nuclei) - Nbframe + 3, colone).Value = (Application.WorksheetFunction.Average(Range(Cells((Nbframe * nuclei) - Nbframe + 4, colone) _
                            , Cells((Nbframe * nuclei) + 2, colone)))) / (Nbframe - f)
                            Cells((Nbframe * nuclei) - Nbframe + 3, colone).Interior.Color = vbBlue
                            Cells((Nbframe * nuclei) - Nbframe + 3, colone).Font.Color = vbWhite
                            If colone > 44 Then
                                Cells((Nbframe * nuclei) - Nbframe + 2, colone).Value = Cells((Nbframe * nuclei) - Nbframe + 3, colone).Value / (4 * Cells(1, colone).Value)
                                Cells((Nbframe * nuclei) - Nbframe + 2, colone).Interior.Color = RGB(128, 128, 128)
                                
                            End If
                        Next colone
                        
                    Else
                     For colone = 44 To 44 + Nbframe - 2
                        For lignes = (Nbframe * nuclei) - Nbframe + 2 To (Nbframe * nuclei) ' - 1
                                Cells(lignes + 2, colone).Value = ((((Cells(lignes + f + 1, Xvalue).Value - Cells(lignes, Xvalue).Value) ^ 2 _
                                + (Cells(lignes + f + 1, Yvalue).Value - Cells(lignes, Yvalue).Value) ^ 2) _
                                + (Cells(lignes + f + 1, Zvalue).Value - Cells(lignes, Zvalue).Value) ^ 2)) * ratio
                                If lignes + f = (Nbframe * nuclei) Then Exit For
                            Next lignes
                            f = f + 1
                            Cells((Nbframe * nuclei) - Nbframe + 3, colone).Value = (Application.WorksheetFunction.Average(Range(Cells((Nbframe * nuclei) - Nbframe + 4, colone) _
                            , Cells((Nbframe * nuclei) + 2, colone)))) / (Nbframe - f)
                            Cells((Nbframe * nuclei) - Nbframe + 3, colone).Interior.Color = vbBlue
                            Cells((Nbframe * nuclei) - Nbframe + 3, colone).Font.Color = vbWhite
                            If colone > 44 Then
                                Cells((Nbframe * nuclei) - Nbframe + 2, colone).Value = Cells((Nbframe * nuclei) - Nbframe + 3, colone).Value / (6 * Cells(1, colone).Value)
                                Cells((Nbframe * nuclei) - Nbframe + 2, colone).Interior.Color = RGB(128, 128, 128)
                            End If
                        Next colone
                    End If
                End If
                colone = 44
                '--------------------------------



Columns("aa:Ae").Clear

'------------------------
' Progression bar
'------------------------
    PctDone = nuclei / Nbnuclei
    UpdateProgressBar PctDone

'------------------------
'go to the next particle
'------------------------
Next nuclei


'----------------------------------
'Average the results
'----------------------------------

If MSD = True Then

ajout2 = 4
colonne = 44
Cells(Nbnuclei + 14 + 2, "ag").Value = "MSD"
Range(Cells(Nbnuclei + 14 + 2, "ag"), Cells(Nbnuclei + 14 + 2, "ai")).Merge
Range(Cells(Nbnuclei + 14 + 2, "ag"), Cells(Nbnuclei + 14 + 2, "ai")).Interior.Color = vbGreen
Range(Cells(Nbnuclei + 14 + 2, "ag"), Cells(Nbnuclei + 14 + 2, "ai")).Font.Bold = True
Cells(Nbnuclei + 14 + 3, "ag").Value = "delta T (" & Listtime.Value & ")"
Cells(Nbnuclei + 14 + 3, "ah").Value = "average"
Cells(Nbnuclei + 14 + 3, "ai").Value = "Error"
Cells(Nbnuclei + 12, "aM").Value = Listdistance.Value & "²/" & Listtime.Value
    For colonne = 44 To Nbframe - 2 + 44
'
        ajout = 3
        For topo = 14 To Nbnuclei + 14
            Cells(Nbnuclei + topo, "aj").Value = Cells(ajout, colonne).Value
            ajout = ajout + Nbframe
        Next topo
        
        Cells(Nbnuclei + 14 + ajout2, "Ah").Value = Application.WorksheetFunction.Average(Range(Cells(Nbnuclei + 14, "aj"), (Cells(Nbnuclei + 20 + topo, "aj"))))
        If Nbnuclei >= 15 Then Cells(Nbnuclei + 14 + ajout2, "Ai").Value = Application.WorksheetFunction.StDev(Range(Cells(Nbnuclei + 14, "aj"), (Cells(Nbnuclei + 20 + topo, "aj")))) / (Nbnuclei ^ 1 / 2) _
        Else Cells(Nbnuclei + 14 + ajout2, "Ai").Value = Application.WorksheetFunction.StDev(Range(Cells(Nbnuclei + 14, "aj"), (Cells(Nbnuclei + 20 + topo, "aj"))))
        Cells(Nbnuclei + 14 + ajout2, "ag").Value = (ajout2 - 3) * TF
        Range(Cells(Nbnuclei + 14, "aj"), Cells(Nbnuclei + 200, "aj")).Clear
        ajout2 = ajout2 + 1
    Next colonne
    ligne = 2
    For burp = 1 To Nbnuclei
        
        Cells(burp + 2, "an").Value = Application.WorksheetFunction.Average(Range(Cells(ligne, 45), (Cells(ligne, 46 + Nbframe))))
        ligne = ligne + Nbframe
    Next burp
End If



If Nbnuclei = 1 Then GoTo pass

Cells(Nbnuclei + 4, "aj").Value = "Compilation:"
Cells(Nbnuclei + 4, "aM").Value = "Units"
Cells(Nbnuclei + 5, "aM").Value = Listtime.Value
Cells(Nbnuclei + 7, "aM").Value = Listdistance.Value & "/" & Listtime.Value
Cells(Nbnuclei + 9, "aM").Value = Listdistance.Value
Cells(Nbnuclei + 10, "aM").Value = Listtime.Value



    If Nbnuclei >= 15 Then Cells(Nbnuclei + 4, "al").Value = "SEM" Else Cells(Nbnuclei + 4, "al").Value = "StDev"
    Cells(Nbnuclei + 4, "ak").Value = "median"
    Cells(Nbnuclei + 5, "aj").Value = "total time pausing"
    Cells(Nbnuclei + 5, "ak").Value = Application.WorksheetFunction.Median(Range("ah3", Cells(Nbnuclei + 2, "ah")))
    If Nbnuclei >= 15 Then Cells(Nbnuclei + 5, "al").Value = (Application.WorksheetFunction.StDev(Range(Cells(3, "ah"), Cells(Nbnuclei + 2, "ah")))) / Sqr(Nbnuclei) Else _
    Cells(Nbnuclei + 5, "al").Value = Application.WorksheetFunction.StDev(Range(Cells(3, "ah"), (Cells(Nbnuclei + 2, "ah"))))

    Cells(Nbnuclei + 6, "aj").Value = "% of time in motion"
    Cells(Nbnuclei + 6, "ak").Value = Application.WorksheetFunction.Median(Range(Cells(3, "ai"), Cells(Nbnuclei + 2, "ai")))
    If Nbnuclei >= 15 Then Cells(Nbnuclei + 6, "al").Value = (Application.WorksheetFunction.StDev(Range(Cells(3, "ai"), Cells(Nbnuclei + 2, "ai")))) / Sqr(Nbnuclei) Else _
    Cells(Nbnuclei + 6, "al").Value = Application.WorksheetFunction.StDev(Range(Cells(3, "ai"), Cells(Nbnuclei + 2, "ai")))

    Cells(Nbnuclei + 7, "aj").Value = "Speed in motion"
    Cells(Nbnuclei + 7, "ak").Value = Application.WorksheetFunction.Median(Range("aj3", Cells(Nbnuclei + 2, "aj")))
    If Nbnuclei >= 15 Then Cells(Nbnuclei + 7, "al").Value = (Application.WorksheetFunction.StDev(Range("aj3", Cells(Nbnuclei + 2, "aj")))) / Sqr(Nbnuclei) Else _
    Cells(Nbnuclei + 7, "al").Value = Application.WorksheetFunction.StDev(Range(Cells(3, "aj"), Cells(Nbnuclei + 2, "aj")))

    Cells(Nbnuclei + 8, "aj").Value = "Number of pauses"
    Cells(Nbnuclei + 8, "ak").Value = Application.WorksheetFunction.Median(Range("ak3", Cells(Nbnuclei + 2, "ak")))
    If Nbnuclei >= 15 Then Cells(Nbnuclei + 8, "al").Value = (Application.WorksheetFunction.StDev(Range("ak3", Cells(Nbnuclei + 2, "ak")))) / Sqr(Nbnuclei) Else _
    Cells(Nbnuclei + 8, "al").Value = Application.WorksheetFunction.StDev(Range(Cells(3, "ak"), Cells(Nbnuclei + 2, "ak")))

    Cells(Nbnuclei + 9, "aj").Value = "Distance"
    Cells(Nbnuclei + 9, "ak").Value = Application.WorksheetFunction.Median(Range("al3", Cells(Nbnuclei + 2, "al")))
    If Nbnuclei >= 15 Then Cells(Nbnuclei + 9, "al").Value = (Application.WorksheetFunction.StDev(Range(Cells(3, "al"), Cells(Nbnuclei + 2, "al")))) / Sqr(Nbnuclei) Else _
    Cells(Nbnuclei + 9, "al").Value = Application.WorksheetFunction.StDev(Range(Cells(3, "al"), Cells(Nbnuclei + 2, "al")))

    Cells(Nbnuclei + 10, "aj").Value = "Duration of pauses"
    Cells(Nbnuclei + 10, "ak").Value = Application.WorksheetFunction.Median(Range("ag3", Cells(Nbnuclei + 2, "ag")))
    If Nbnuclei >= 15 Then Cells(Nbnuclei + 10, "al").Value = (Application.WorksheetFunction.StDev(Range(Cells(3, "ag"), Cells(Nbnuclei + 2, "ag")))) / Sqr(Nbnuclei) Else _
    Cells(Nbnuclei + 10, "al").Value = Application.WorksheetFunction.StDev(Range(Cells(3, "ag"), Cells(Nbnuclei + 2, "ag")))

    If Persistence = True Then
        Cells(Nbnuclei + 11, "aj").Value = "Persistence"
        Cells(Nbnuclei + 11, "ak").Value = Application.WorksheetFunction.Median(Range("am3", Cells(Nbnuclei + 2, "am")))
            If Nbnuclei >= 15 Then Cells(Nbnuclei + 11, "al").Value = (Application.WorksheetFunction.StDev(Range(Cells(3, "am"), Cells(Nbnuclei + 2, "am")))) / Sqr(Nbnuclei) Else _
            Cells(Nbnuclei + 11, "al").Value = Application.WorksheetFunction.StDev(Range(Cells(3, "am"), Cells(Nbnuclei + 2, "am")))
    End If
    
    If MSD = True Then
        Cells(Nbnuclei + 12, "aj").Value = "Diffusion coefficient (d²/t)"
        Cells(Nbnuclei + 12, "ak").Value = Application.WorksheetFunction.Median(Range("an3", Cells(Nbnuclei + 2, "an")))
        Cells(Nbnuclei + 12, "al").Value = Application.WorksheetFunction.StDev(Range("an3", Cells(Nbnuclei + 2, "an"))) / (Nbnuclei ^ 1 / 2)
    End If


Columns("ag:aq").AutoFit


'----------------------------
'Format the result table
'----------------------------

Range(Cells(Nbnuclei + 4, "aj"), Cells(Nbnuclei + 12, "am")).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.NumberFormat = "0.000"
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    
    

pass:


    
'-------------------------------------------------------------------
'Draw the graphs at the end of analysis if option selected
'-------------------------------------------------------------------

If Trackgraph = True Then


b = 1
For h = 1 To Nbnuclei

    Dim rngDataSource As Range
    Dim rgnDataSource2 As Range
    Dim iDataRowsCt As Long
    Dim iSrsIx As Integer
    Dim chtChart As Chart
    Dim srsNew As Series
    Dim rng As Range
    
    down = h * Nbframe + 1
    Set rngDataSource = Range(Cells(down - Nbframe + 1, Xvalue), Cells(down, Yvalue))
    
    Set rng = ActiveSheet.Range(Cells(b, "x"), Cells(b + 25, "x"))
    With rngDataSource
        iDataRowsCt = .Rows.Count
        
        End With

 
    ' Create the chart
    
    Set chtChart = ActiveSheet.ChartObjects.Add(Left:=rng.Left, _
    Width:=ActiveWindow.Width / 3, _
    Top:=rng.Top + 250 + _
    ActiveWindow.Height / 25, _
    Height:=ActiveWindow.Height / 2).Chart
   
    With chtChart
        .ChartType = xlXYScatterSmooth
        .Parent.Name = "nuclei " & h
        .HasTitle = True
        .ChartTitle.Characters.Text = "Particle " & h
        'X axis name
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = Listdistance.Value
        'y-axis name
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = Listdistance.Value
        ' Remove any series created with the chart
            Do Until .SeriesCollection.Count = 0
            .SeriesCollection(1).Delete
            Loop
        
        For iSrsIx = 1 To iDataRowsCt Step Nbframe
        
        ' Add the tracking before the two threshold
        
        Set srsNew = .SeriesCollection.NewSeries
            With srsNew
            .Name = "Trajectory"
            .XValues = rngDataSource.Cells(iSrsIx, 2).Resize(Nbframe, 1)
            .Values = rngDataSource.Cells(iSrsIx, 1).Resize(Nbframe, 1)
            
            End With
        
            
        Next
    End With
    b = b + 22
Next h

'----------------------------------
'Trace graph after 2nd threshold
'----------------------------------
Dim iPoint As Long
For h = 1 To NumCharts Step 1
    Set rngXs = Range(Cells(h * Nbframe - Nbframe + 2, "v"), Cells(h * Nbframe + 1, "v"))
    Set rngYs = Range(Cells(h * Nbframe - Nbframe + 2, "u"), Cells(h * Nbframe + 1, "u"))
    ActiveSheet.ChartObjects(h).Activate
    With ActiveChart
    Set sernew = .SeriesCollection.NewSeries
        With sernew
        .Name = "after SkyPad"
        .XValues = rngXs
        .Values = rngYs
        .MarkerSize = 5
        .MarkerStyle = xlMarkerStyleCircle
        With .Format.Line
        .Visible = msoFalse
    End With
        End With
    End With
Next h
End If

'----------------------------------
'Trace MSD over time
'----------------------------------

If MSD = True Then

    Dim rngDataSource3 As Range
    Dim rgnDataSource4 As Range
    Dim iDataRowsCt2 As Long
    Dim iSrsIx2 As Integer
    Dim chtChart2 As Chart
    Dim srsNew2 As Series
    Dim rng2 As Range
    Set rngDataSource3 = Range(Cells(Nbnuclei + 19, "AG"), Cells(Nbnuclei + 18 + Nbframe, "ai"))
    Set rng2 = ActiveSheet.Range(Cells(Nbnuclei + 20, "AG"), Cells(Nbnuclei + 25 + Nbframe, "ai"))
    Set rngErrX = Range(Cells(Nbnuclei + 19, "AI"), Cells(Nbnuclei + 17 + Nbframe, "aI"))
    Set rngErrY = Range(Cells(Nbnuclei + 19, "AI"), Cells(Nbnuclei + 17 + Nbframe, "aI"))
 
    ' Create the chart
    
    Set chtChart2 = ActiveSheet.ChartObjects.Add(Left:=rng2.Left + 350, _
    Width:=ActiveWindow.Width / 3, _
    Top:=rng2.Top + _
    ActiveWindow.Height / 25, _
    Height:=ActiveWindow.Height / 2).Chart
   
    With chtChart2
        .ChartType = xlXYScatterSmooth
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Frame intervals"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "MSD"
        ' Remove any series created with the chart
            Do Until .SeriesCollection.Count = 0
            .SeriesCollection(1).Delete
            Loop
         'Add the tracking before the two threshold
        Set srsNew2 = .SeriesCollection.NewSeries
            With srsNew2
            .Name = "MSD over time intervals"
            .Values = rngDataSource3.Cells(iSrsIx2, 2).Resize(Nbframe, 1)
            .XValues = rngDataSource3.Cells(iSrsIx2, 1).Resize(Nbframe, 1)
            .ErrorBar Direction:=xlX, Include:=xlErrorBarIncludeBoth, Type:=xlCustom, Amount:=rngErrX
            .ErrorBar Direction:=xlY, Include:=xlErrorBarIncludeBoth, Type:=xlCustom, MinusValues:=rngErrY
            End With
    End With
    
End If

Ending:
Columns("ag:aq").AutoFit

With Range(Range("ao2"), Range("ap13"))
    .Interior.Color = vbBlack
    .Font.Color = vbWhite
    .HorizontalAlignment = xlRight
End With

Range("ap9").Interior.Color = vbBlack
Range("ap9").Font.Color = vbWhite

With Range(Cells(2, "af"), Cells(Nbnuclei + 2, "an"))
    .Interior.Color = RGB(128, 128, 128)
    .Font.Color = vbWhite
    End With
Range(Cells(2, "aj"), Cells(Nbnuclei + 2, "aj")).NumberFormat = "0.000"
Range(Cells(2, "al"), Cells(Nbnuclei + 2, "am")).NumberFormat = "0.000"
Range(Cells(2, "an"), Cells(Nbnuclei + 2, "an")).NumberFormat = "0.000"
With Range(Cells(Nbnuclei + 4, "aj"), Cells(Nbnuclei + 12, "am"))
    .Interior.Color = vbGreen
    .HorizontalAlignment = xlRight
    End With
Range(Cells(Nbnuclei + 4, "aj"), Cells(Nbnuclei + 12, "aj")).Font.Bold = True
Range(Cells(Nbnuclei + 4, "ak"), Cells(Nbnuclei + 4, "am")).Font.Bold = True
Range(Cells("ao2"), Cells("ao13")).Font.Bold = True
Range(Cells(Nbnuclei + 12, "ak"), Cells(Nbnuclei + 12, "al")).NumberFormat = "0.000"
Cells(Nbnuclei + 14, "aj").Font.Italic = True
Cells(Nbnuclei + 4, "ag").Font.Bold = True

Unload SkyP

Range("y1:Ap9").Select
Range(Cells(Nbnuclei, "ae"), Cells(Nbnuclei + 8, "al")).Select
ActiveWindow.ScrollRow = Selection.Row
ActiveWindow.ScrollColumn = Selection.Column
Range(Cells(Nbnuclei + 4, "aj"), Cells(Nbnuclei + 12, "am")).Select
End Sub

Private Sub NameBouton_Annulation_Click()
Unload SkyP
End Sub


Private Sub OptionButton1_Click()

End Sub

Private Sub TabStrip3_Change()

End Sub

Private Sub Only_graph_Click()

End Sub

Private Sub Persistence_Click()

End Sub

Private Sub UserForm_Click()

End Sub

Sub UpdateProgressBar(PctDone As Single)
    With SkyP

        ' Update the Caption property of the Frame control.
        .Frameprogress.Caption = Format(PctDone, "0%")

        ' Widen the Label control.
        .Labelprogress.Width = PctDone * _
            (.Frameprogress.Width - 10)
    End With

    ' The DoEvents allows the UserForm to update.
    DoEvents
End Sub

Comments