Hello, i've been trying to code a very difficult table using VBA and userforms. So i use userforms to fetch measures that needs to be put in a table. So here is what i did so far (doesn't work though)

private sub Button_command()

Insertmeasures l_ouvrage, la_date, a, c, d, g, f, cod, co, hs                        'this calls the function to insert measures in the table

end sub


Private Sub InsertMeasures(Xouvrage As String, Xdate As Date, Xval1 As Double, Xval3 As Double, Xval4 As Double, Xval5 As Double, Xval6 As Double, Xval7 As Double, Xval8 As Double, Xval9 As Double)

numligne = CalculLign(Xouvrage, Xdate)                      'This function is called to calculate the starting row

Sheets("DATAGAZ").Cells(numligne, 1) = Xouvrage
Sheets("DATAGAZ").Cells(numligne, 2) = CStr(Xdate)
Sheets("DATAGAZ").Cells(numligne, 11) = CStr(Xval1)
Sheets("DATAGAZ").Cells(numligne, 7) = CStr(Xval3)
Sheets("DATAGAZ").Cells(numligne, 8) = CStr(Xval4)
Sheets("DATAGAZ").Cells(numligne, 3) = CStr(Xval5)
Sheets("DATAGAZ").Cells(numligne, 5) = CStr(Xval6)
Sheets("DATAGAZ").Cells(numligne, 6) = CStr(Xval7)
Sheets("DATAGAZ").Cells(numligne, 9) = CStr(Xval8)
Sheets("DATAGAZ").Cells(numligne, 10) = CStr(Xval9)
Sheets("DATAGAZ").Select
ActiveSheet.ListObjects("Table2").ListRows.Add (numligne)

End Sub

Private Function CalculLign(ouv As String, dat As Date) As Integer
Set tbl = Sheets("DATAGAZ").ListObjects("Table2")

    nbLignes = tbl.Range.Rows.Count
    'nbCols = ActiveWorkbook.Sheets("data").UsedRange.Columns.Count
    CalculerLigne = nbLignes
    For i = 2 To nbLignes
        If (Cells(i, 1).Value = ouv) Then
            cpt = i
            Do
                cpt = cpt + 1
            Loop While (Cells(cpt, 1).Value = ouv)
            CalculerLigne = cpt
        End If
    Next
End Function
I want it to recognize the name of the "ouvrage". If there are already measures in the table of that same "ouvrage" then the code will insert a new row under it and paste the measures in the cells. But if there is no measure of that "ouvrage" yet, then it would paste one row under the previous measurements. (which is a pain in the a** to code)

It should look like this

\1

help me please