Code VBA Excel Cmdupdate

Bonsoir Forum,

S’il vous plaît, j’ai un problème avec ce code, il trouver concernée par la recherche, au lieu d’apporter les modifications apportées dans l' userform, il ajoute une nouvelle ligne en bas

Private Sub Cmdupdate2_Click()
    On Error Resume Next
    Dim UpRow2 As Range
    Set UpRow2 = DataSheet.Range("A1:A10000").Find(Me.Txtsearch1.Value, LookIn:=xlValues, LookAt:=xlWhole)

    If Not UpRow2 Is Nothing Then
        With DataSheet
            .Cells(UpRow2.Row, "A").Value = Me.TextBox2.Value
            .Cells(UpRow2.Row, "B").Value = Me.TextBox3.Value
            .Cells(UpRow2.Row, "C").Value = Me.TextBox4.Value
            .Cells(UpRow2.Row, "D").Value = Me.ComboBox10.Value
            .Cells(UpRow2.Row, "E").Value = Me.TextBox5.Value
            .Cells(UpRow2.Row, "F").Value = Me.TextBox6.Value
            .Cells(UpRow2.Row, "G").Value = Me.TextBox7.Value
            .Cells(UpRow2.Row, "H").Value = Me.ComboBox2.Value
            .Cells(UpRow2.Row, "I").Value = Me.ComboBox12.Value
            .Cells(UpRow2.Row, "J").Value = Me.ComboBox1.Value
            .Cells(UpRow2.Row, "K").Value = Me.TextBox18.Value
            .Cells(UpRow2.Row, "L").Value = Me.ComboBox9.Value
            .Cells(UpRow2.Row, "M").Value = Me.TextBox19.Value
            .Cells(UpRow2.Row, "N").Value = Me.ComboBox4.Value
            .Cells(UpRow2.Row, "O").Value = Me.ComboBox5.Value
            .Cells(UpRow2.Row, "P").Value = Me.TextBox13.Value
            .Cells(UpRow2.Row, "Q").Value = Me.TextBox14.Value
            .Cells(UpRow2.Row, "R").Value = Me.ComboBox6.Value
            .Cells(UpRow2.Row, "S").Value = Me.ComboBox7.Value
            .Cells(UpRow2.Row, "T").Value = Me.ComboBox11.Value
            .Cells(UpRow2.Row, "V").Value = Me.TextBox21.Value
            .Cells(UpRow2.Row, "W").Value = Me.TextBox22.Value

            ' Code pour modifier l'image
            Dim LstPath1 As String, PcName1 As String
            LstPath1 = .Cells(UpRow2.Row, "X").Value
            If LstPath1 <> "" Then
                Kill LstPath1
            End If
            PcName1 = Me.TextBox23.Text
            SavePicture Me.Image1.Picture, ThisWorkbook.Path & "\" & PcName1 & ".JPEG"
            .Cells(UpRow2.Row, "X").Value = ThisWorkbook.Path & "\" & PcName1 & ".JPEG"
        End With

        MsgBox "Données enregistrées avec succès", vbInformation + vbMsgBoxRight + vbMsgBoxRtlReading, "HICHAM"
        ThisWorkbook.Save
    Else
        MsgBox "Données introuvables", vbExclamation + vbMsgBoxRight + vbMsgBoxRtlReading, "Hicham - Avertissement"
    End If
End Sub

Merci à tous pour le temps que vous avez pris sur mon problème.

Bonjour Forum,

J’ai trouvé la solution et je l’ai mise ici pour ceux qui la voulaient, le problème était dans

Txtsearch1

Set UpRow2 = DataSheet.Range("A1:A10000").Find(Me.Txtsearch2.Value, LookIn:=xlValues, LookAt:=xlWhole)
Private Sub Cmdupdate2_Click()
    On Error Resume Next
    Dim UpRow2 As Range
    Set UpRow2 = DataSheet.Range("A1:A10000").Find(Me.Txtsearch2.Value, LookIn:=xlValues, LookAt:=xlWhole)

    If Not UpRow2 Is Nothing Then
        With DataSheet
            .Cells(UpRow2.Row, "A").Value = Me.TextBox2.Value
            .Cells(UpRow2.Row, "B").Value = Me.TextBox3.Value
            .Cells(UpRow2.Row, "C").Value = Me.TextBox4.Value
            .Cells(UpRow2.Row, "D").Value = Me.ComboBox10.Value
            .Cells(UpRow2.Row, "E").Value = Me.TextBox5.Value
            .Cells(UpRow2.Row, "F").Value = Me.TextBox6.Value
            .Cells(UpRow2.Row, "G").Value = Me.TextBox7.Value
            .Cells(UpRow2.Row, "H").Value = Me.ComboBox2.Value
            .Cells(UpRow2.Row, "I").Value = Me.ComboBox12.Value
            .Cells(UpRow2.Row, "J").Value = Me.ComboBox1.Value
            .Cells(UpRow2.Row, "K").Value = Me.TextBox18.Value
            .Cells(UpRow2.Row, "L").Value = Me.ComboBox9.Value
            .Cells(UpRow2.Row, "M").Value = Me.TextBox19.Value
            .Cells(UpRow2.Row, "N").Value = Me.ComboBox4.Value
            .Cells(UpRow2.Row, "O").Value = Me.ComboBox5.Value
            .Cells(UpRow2.Row, "P").Value = Me.TextBox13.Value
            .Cells(UpRow2.Row, "Q").Value = Me.TextBox14.Value
            .Cells(UpRow2.Row, "R").Value = Me.ComboBox6.Value
            .Cells(UpRow2.Row, "S").Value = Me.ComboBox7.Value
            .Cells(UpRow2.Row, "T").Value = Me.ComboBox11.Value
            .Cells(UpRow2.Row, "V").Value = Me.TextBox21.Value
            .Cells(UpRow2.Row, "W").Value = Me.TextBox22.Value

            ' Code pour modifier l'image
            Dim LstPath1 As String, PcName1 As String
            LstPath1 = .Cells(UpRow2.Row, "X").Value
            If LstPath1 <> "" Then
                Kill LstPath1
            End If
            PcName1 = Me.TextBox23.Text
            SavePicture Me.Image1.Picture, ThisWorkbook.Path & "\" & PcName1 & ".JPEG"
            .Cells(UpRow2.Row, "X").Value = ThisWorkbook.Path & "\" & PcName1 & ".JPEG"
        End With

        MsgBox "Données enregistrées avec succès", vbInformation + vbMsgBoxRight + vbMsgBoxRtlReading, "HICHAM"
        ThisWorkbook.Save
    Else
        MsgBox "Données introuvables", vbExclamation + vbMsgBoxRight + vbMsgBoxRtlReading, "Hicham - Avertissement"
    End If
End Sub
Rechercher des sujets similaires à "code vba cmdupdate"