1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| Private Sub Env_Don_Click()
Dim madate As Date
Dim ligne As Integer
Dim oWksht As Worksheet
Dim lastrow As Long
Dim myCell As Range
madate = CDate(Me.Date_Txt.Text)
Sheets("Feuil1").Select
Sheets("Feuil1").Unprotect "543210"
Range("C6") = TextBox1.Value
Range("C7") = TextBox2.Value
Range("C8") = TextBox3.Value
Range("C9") = TextBox4.Value
Range("C10") = TextBox5.Value
Range("C11") = TextBox6.Value
Range("B32").Value = TextBox7.Text
Range("G4") = Date_Txt.Text
Range("C16") = TextBox8.Value
Range("C17") = TextBox9.Value
Range("C18") = TextBox10.Value
Sheets("Feuil1").Protect "543210"
Sheets("Feuil2").Visible = True
Sheets("Feuil2").Select
Set oWksht = Sheets("Feuil2")
lastrow = oWksht.Range("A" & Rows.Count).End(xlUp).Row 'Rows.Count descend a la dernière ligne de la feuil1 plage A puis remonte avec .End(xlUp).row a la dernière ligne remplie et en prend la valeur
Range("A1").Activate
Set myCell = oWksht.Range("A14:A" & lastrow).Find(what:=madate, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If myCell Is Nothing Then
MsgBox ("Date incorrect.")
ElseIf Not myCell.Offset(0, 1) = "" Then 'si la cellule a droite de la date n'est pas vide
Select Case MsgBox("Ce rapport a déja été crée êtes vous sur de vouloir écraser les données", vbOKCancel, "Ecraser les données")
Case vbOK
ligne = myCell.Row 'Ligne de la date
Sheets("Feuil2").Cells(ligne, 2).Value = TextBox1.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 3).Value = TextBox2.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 4).Value = TextBox3.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 5).Value = TextBox4.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 6).Value = TextBox5.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 7).Value = TextBox6.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 8).Value = TextBox7.Text 'commentaire
Sheets("Feuil2").Cells(ligne, 9).Value = TextBox8.Text 'accident
Sheets("Feuil2").Cells(ligne, 10).Value = TextBox9.Text 'accident
Sheets("Feuil2").Cells(ligne, 11).Value = TextBox10.Text 'accident
Case vbCancel
End Select
Else
ligne = myCell.Row 'Ligne de la date
Sheets("Feuil2").Cells(ligne, 2).Value = TextBox1.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 3).Value = TextBox2.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 4).Value = TextBox3.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 5).Value = TextBox4.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 6).Value = TextBox5.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 7).Value = TextBox6.Text 'Parcipant
Sheets("Feuil2").Cells(ligne, 8).Value = TextBox7.Text 'commentaire
Sheets("Feuil2").Cells(ligne, 9).Value = TextBox8.Text 'accident
Sheets("Feuil2").Cells(ligne, 10).Value = TextBox9.Text 'accident
Sheets("Feuil2").Cells(ligne, 11).Value = TextBox10.Text 'accident
End If
ActiveWindow.SelectedSheets.Visible = False
End Sub |
Partager