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
| Private Sub cmBtn_Modify_Click()
Dim ws As Worksheet
Dim foundRow As Range
Dim originalValues As Variant
Dim selectedValue As String
' Récupérer la valeur sélectionnée
selectedValue = Me.ComboBox1.value
' Set the worksheet where you want to make modifications
Set ws = ThisWorkbook.Sheets("2024")
' Assuming you have a way to find the row, for example:
Set foundRow = ws.Columns("B:B").Find(What:=selectedValue, LookIn:=xlValues, LookAt:=xlWhole) ' You should replace this with your actual code to find the row
foundRow.Offset(0, 7).NumberFormat = "dd/MM/yyyy"
foundRow.Offset(0, 8).NumberFormat = "dd/MM/yyyy"
foundRow.Offset(0, 9).NumberFormat = "dd/MM/yyyy"
foundRow.Offset(0, 10).NumberFormat = "dd/MM/yyyy"
foundRow.Offset(0, 12).NumberFormat = "dd/MM/yyyy"
' Store original values before modification
originalValues = Array(Me.EchelGrade.value, Me.Departement.value, Me.ChiefofDept.value, Format(Me.EnvoiSign.value, "dd/MM/yyyy"), _
Format(Me.RetourSign.value, "dd/MM/yyyy"), Me.NumAvis.value, Format(Me.DateAvis.value, "dd/MM/yyyy"), _
Format(Me.DateCandidat.value, "dd/MM/yyyy"), Format(Me.DateRepCandidat.value, "dd/MM/yyyy"), Me.StatusDossier.value)
' Update the values
foundRow.Offset(0, 6).value = Me.EchelGrade.value
foundRow.Offset(0, 4).value = Me.Departement.value
foundRow.Offset(0, 5).value = Me.ChiefofDept.value
foundRow.Offset(0, 9).value = Format(Me.EnvoiSign.value, "dd/MM/yyyy")
foundRow.Offset(0, 10).value = Format(Me.RetourSign.value, "dd/MM/yyyy")
foundRow.Offset(0, 11).value = Me.NumAvis.value
foundRow.Offset(0, 12).value = Format(Me.DateAvis.value, "dd/MM/yyyy")
foundRow.Offset(0, 7).value = Format(Me.DateCandidat.value, "dd/MM/yyyy")
foundRow.Offset(0, 8).value = Format(Me.DateRepCandidat.value, "dd/MM/yyyy")
foundRow.Offset(0, 13).value = Me.StatusDossier.value
' Check for modifications and modify only changed cells
If Not ArraysEqual(originalValues, Array(Me.EchelGrade.value, Me.Departement.value, Me.ChiefofDept.value, Format(Me.EnvoiSign.value, "dd/MM/yyyy"), _
Format(Me.RetourSign.value, "dd/MM/yyyy"), Me.NumAvis.value, Format(Me.DateAvis.value, "dd/MM/yyyy"), _
Format(Me.DateCandidat.value, "dd/MM/yyyy"), Format(Me.DateRepCandidat.value, "dd/MM/yyyy"), Me.StatusDossier.value)) Then
' Perform your actions to modify the changed cells here
' For example:
ws.Cells(foundRow.Row, "D").value = Me.EchelGrade.value
ws.Cells(foundRow.Row, "F").value = Me.Departement.value
ws.Cells(foundRow.Row, "G").value = Me.ChiefofDept.value
ws.Cells(foundRow.Row, "K").value = Format(Me.EnvoiSign.value, "dd\/mm\/yyyy")
ws.Cells(foundRow.Row, "L").value = Format(Me.RetourSign.value, "dd/MM/yyyy")
ws.Cells(foundRow.Row, "M").value = Me.NumAvis.value
ws.Cells(foundRow.Row, "N").value = Format(Me.DateAvis.value, "dd/MM/yyyy")
ws.Cells(foundRow.Row, "I").value = Format(Me.DateCandidat.value, "dd/MM/yyyy")
ws.Cells(foundRow.Row, "J").value = Format(Me.DateRepCandidat.value, "dd/MM/yyyy")
'ws.Cells(foundRow.Row, "D").value = Me.EchelGrade.value
'ws.Cells(foundRow.Row, "G").value = Me.Departement.value
' ...
End If
End Sub |
Partager