VBA / Erreur d'exécution 1004

Résolu
Bonjour,

J'ai un formulaire me permettant de modifier toutes les cellules d'une ligne préalablement sélectionnée. Quand je double-clique sur la ligne voulue, j'ai le formulaire qui apparaît. Lorsque je ferme ce dernier (sans avoir fait de modification ou après avoir édité mon classeur) j'ai une erreur 1004 qui apparaît et qui me surligne la ligne suivante :

    .Cells(LaligneFiltre, i) = Me.Controls("Textbox" & i).Value


Voici le code de mon userform :
Option Explicit
Dim i As Long
Private Sub CommandButton1_Click()
With Sheets("FILTRER")
For i = 1 To 17
.Cells(LaligneTout, i) = Me.Controls("Textbox" & i).Value
Next
.Cells(LaligneTout, "Q") = CDate(Me.TextBox17)
End With
With Sheets("ADAPTATION")
For i = 1 To 17
.Cells(LaligneFiltre, i) = Me.Controls("Textbox" & i).Value
Next
.Cells(LaligneFiltre, "Q") = CDate(Me.TextBox17)
End With
Unload UserForm1
End Sub

Private Sub Frame3_Click()

End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label28_Click()

End Sub

Private Sub Label30_Click()

End Sub

Private Sub Label36_Click()

End Sub

Private Sub UserForm_initialize()
With Sheets("FILTRER")
For i = 1 To 17
Me.Controls("label" & i).Caption = .Cells(3, i)
Me.Controls("Textbox" & i).Value = .Cells(LaligneTout, i)
Next
Me.TextBox6.Value = Format(Me.TextBox6, "hh:mm")
Me.TextBox8.Value = Format(Me.TextBox8, "hh:mm")
Me.TextBox17.Value = Format(Me.TextBox17, "dd/mm/yyyy")
End With
End Sub


Ce formulaire est lancé via la feuille "FILTRE" par ces codes :
Option Explicit
Dim Tmp As String, Tmp1 As String, Plage

Private Sub ComboBox21_Change()
Sheets("FILTRER").Range("a4:aa" & Rows.Count).Clear
If ComboBox21.Value = "" Then Exit Sub
With Sheets("ADAPTATION")
Set Plage = .Range("a2:aa" & .Cells.Find("*", , , , xlByRows, xlPrevious).Row)
Plage.AutoFilter Field:=2, Criteria1:=ComboBox21.Value
Plage.Offset(1).Resize(Plage.Rows.Count - 1, Plage.Columns.Count).SpecialCells(xlCellTypeVisible).Copy Sheets("FILTRER").[a4]
End With
Plage.AutoFilter
End Sub
Private Sub Worksheet_Activate()
Dim F As Worksheet, i As Long, mondico, A(), temp

Set F = Sheets("ADAPTATION")
Set mondico = CreateObject("Scripting.Dictionary")
A = F.Range("b2:b" & F.Cells(F.Rows.Count, "c").End(xlUp).Row)
For i = LBound(A) To UBound(A)
If A(i, 1) <> "" Then mondico(A(i, 1)) = ""
Next i
'--avec tri
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Sheets("FILTRER").ComboBox21.List = temp
'Sheets("FILTRER").ComboBox21.Value = ""
End Sub

Sub Tri(A, gauc, droi) ' Quick sort
Dim Ref As String, g As Long, d As Long, temp
Ref = A((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While A(g) < Ref: g = g + 1: Loop
Do While Ref < A(d): d = d - 1: Loop
If g <= d Then
temp = A(g): A(g) = A(d): A(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(A, g, droi)
If gauc < d Then Call Tri(A, gauc, d)
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim i As Long, c
Cancel = True
With Sheets("FILTRER")
Set Plage = .Range("a4:aa" & .Cells.Find("*", , , , xlByRows, xlPrevious).Row)
End With
If Intersect(Target, Plage) Is Nothing Or [a4] = "" Then Exit Sub
With Sheets("ADAPTATION")
Set Plage = .Range("a3:aa" & .Cells.Find("*", , , , xlByRows, xlPrevious).Row)
End With
Tmp = ""
LaligneTout = Target.Row
For i = 1 To 17: Tmp = Tmp & Cells(Target.Row, i): Next
For Each c In Plage.Rows
Tmp1 = ""
For i = 1 To 17: Tmp1 = Tmp1 & Sheets("ADAPTATION").Cells(c.Row, i): Next
If Tmp = Tmp1 Then LaligneFiltre = c.Row
Next
UserForm1.Show
End Sub


Un module contient deux déclarations :
Option Explicit

Public LaligneFiltre As Long
Public LaligneTout As Long


Je peux vous passer mon fichier test au besoin.
Bien cordialement,

5 réponses

  1. Contributeur
    bonjour, ce serait plus simple avec un fichier où l'erreur se produit.