bonjour quelqu'un pour m'aider en vba excel s'il vous plait
je travail sur une appli vba actuellement et mon code de creation d'article marche pas pour tous les sections j'ai un code pour envoir les données dans deux tableau différents
mais l'application se plante parfois
Option Explicit
Dim lo As ListObject
Private Sub CommandButton1_Click()
Dim i As Integer
Dim M As Integer
Dim s As String
Dim N As String
Dim W As String
If TextBox2.Value = "" Or TextBox3.Value = "" Or ComboBox1.Value = "" Or TextBox8.Value = "" Then
MsgBox "Tous les champs sont obligatoires"
TextBox2.Value = ""
TextBox3.Value = ""
ComboBox1.Value = ""
TextBox8.Value = ""
Else
i = 1
ThisWorkbook.Worksheets("article section electricité").Activate
M = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To M
If ThisWorkbook.Worksheets("article section electricité").Range("B" & i).Value = TextBox2.Value Then
MsgBox "Article existe deja"
TextBox2.Value = ""
TextBox3.Value = ""
ComboBox1.Value = ""
TextBox8.Value = ""
Exit Sub
End If
Next
While ThisWorkbook.Worksheets("article section electricité").Range("A" & i).Value <> ""
i = i + 1
Wend
ThisWorkbook.Worksheets("article section electricité").Range("A" & i).Value = TextBox2.Value
ThisWorkbook.Worksheets("article section electricité").Range("B" & i).Value = TextBox3.Value
ThisWorkbook.Worksheets("article section electricité").Range("C" & i).Value = ComboBox1.Value
ThisWorkbook.Worksheets("article section electricité").Range("D" & i).Value = TextBox8.Value
N = 1
While ThisWorkbook.Worksheets("Stock electricité").Range("A" & i).Value <> ""
N = i + 1
Wend
ThisWorkbook.Worksheets("Stock electricité").Range("A" & i).Value = TextBox2.Value
ThisWorkbook.Worksheets("Stock electricité").Range("B" & i).Value = TextBox3.Value
ThisWorkbook.Worksheets("Stock electricité").Range("C" & i).Value = 0
ThisWorkbook.Worksheets("Stock electricité").Range("D" & i).Value = TextBox8.Value
ThisWorkbook.Worksheets("Stock electricité").Range("E" & i).Value = "=D*C:C"
W = 1
While ThisWorkbook.Worksheets("Stock total").Range("A" & i).Value <> ""
W = i + 1
Wend
ThisWorkbook.Worksheets("Stock total").Range("A" & i).Value = TextBox2.Value
ThisWorkbook.Worksheets("Stock total").Range("B" & i).Value = TextBox3.Value
ThisWorkbook.Worksheets("Stock total").Range("C" & i).Value = 0
ThisWorkbook.Worksheets("Stock total").Range("D" & i).Value = TextBox8.Value
ThisWorkbook.Worksheets("Stock total").Range("E" & i).Value = "=D*C:C"
On Error GoTo GestionErreur
' Votre code ici
Exit Sub
GestionErreur:
' Code de gestion d'erreur
MsgBox "Une erreur s'est produite : " & Err.Description
MsgBox "Article Bien enregistrer !"
TextBox2.Value = ""
TextBox3.Value = ""
ComboBox1.Value = ""
TextBox8.Value = ""
End If
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
Private Sub CommandButton5_Click()
creationfournisseur.Show
End Sub
Private Sub TextBox3_AfterUpdate()
Dim i As Integer
Dim M As Integer
i = 1
Set lo = Worksheets("Suppliers").Range("Tableau6").ListObject
Me.ComboBox1.List = lo.ListColumns(1).DataBodyRange.Value
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer
Dim M As Integer
i = 1
ThisWorkbook.Worksheets("article section electricité").Activate
M = Cells(Rows.Count, "A").End(xlUp).Row
While ThisWorkbook.Worksheets("article section electricité").Range("A" & i).Value <> ""
i = i + 1
Wend
TextBox2.Value = " AC000" & i
End Sub
je travail sur une appli vba actuellement et mon code de creation d'article marche pas pour tous les sections j'ai un code pour envoir les données dans deux tableau différents
mais l'application se plante parfois
Option Explicit
Dim lo As ListObject
Private Sub CommandButton1_Click()
Dim i As Integer
Dim M As Integer
Dim s As String
Dim N As String
Dim W As String
If TextBox2.Value = "" Or TextBox3.Value = "" Or ComboBox1.Value = "" Or TextBox8.Value = "" Then
MsgBox "Tous les champs sont obligatoires"
TextBox2.Value = ""
TextBox3.Value = ""
ComboBox1.Value = ""
TextBox8.Value = ""
Else
i = 1
ThisWorkbook.Worksheets("article section electricité").Activate
M = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To M
If ThisWorkbook.Worksheets("article section electricité").Range("B" & i).Value = TextBox2.Value Then
MsgBox "Article existe deja"
TextBox2.Value = ""
TextBox3.Value = ""
ComboBox1.Value = ""
TextBox8.Value = ""
Exit Sub
End If
Next
While ThisWorkbook.Worksheets("article section electricité").Range("A" & i).Value <> ""
i = i + 1
Wend
ThisWorkbook.Worksheets("article section electricité").Range("A" & i).Value = TextBox2.Value
ThisWorkbook.Worksheets("article section electricité").Range("B" & i).Value = TextBox3.Value
ThisWorkbook.Worksheets("article section electricité").Range("C" & i).Value = ComboBox1.Value
ThisWorkbook.Worksheets("article section electricité").Range("D" & i).Value = TextBox8.Value
N = 1
While ThisWorkbook.Worksheets("Stock electricité").Range("A" & i).Value <> ""
N = i + 1
Wend
ThisWorkbook.Worksheets("Stock electricité").Range("A" & i).Value = TextBox2.Value
ThisWorkbook.Worksheets("Stock electricité").Range("B" & i).Value = TextBox3.Value
ThisWorkbook.Worksheets("Stock electricité").Range("C" & i).Value = 0
ThisWorkbook.Worksheets("Stock electricité").Range("D" & i).Value = TextBox8.Value
ThisWorkbook.Worksheets("Stock electricité").Range("E" & i).Value = "=D*C:C"
W = 1
While ThisWorkbook.Worksheets("Stock total").Range("A" & i).Value <> ""
W = i + 1
Wend
ThisWorkbook.Worksheets("Stock total").Range("A" & i).Value = TextBox2.Value
ThisWorkbook.Worksheets("Stock total").Range("B" & i).Value = TextBox3.Value
ThisWorkbook.Worksheets("Stock total").Range("C" & i).Value = 0
ThisWorkbook.Worksheets("Stock total").Range("D" & i).Value = TextBox8.Value
ThisWorkbook.Worksheets("Stock total").Range("E" & i).Value = "=D*C:C"
On Error GoTo GestionErreur
' Votre code ici
Exit Sub
GestionErreur:
' Code de gestion d'erreur
MsgBox "Une erreur s'est produite : " & Err.Description
MsgBox "Article Bien enregistrer !"
TextBox2.Value = ""
TextBox3.Value = ""
ComboBox1.Value = ""
TextBox8.Value = ""
End If
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
Private Sub CommandButton5_Click()
creationfournisseur.Show
End Sub
Private Sub TextBox3_AfterUpdate()
Dim i As Integer
Dim M As Integer
i = 1
Set lo = Worksheets("Suppliers").Range("Tableau6").ListObject
Me.ComboBox1.List = lo.ListColumns(1).DataBodyRange.Value
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer
Dim M As Integer
i = 1
ThisWorkbook.Worksheets("article section electricité").Activate
M = Cells(Rows.Count, "A").End(xlUp).Row
While ThisWorkbook.Worksheets("article section electricité").Range("A" & i).Value <> ""
i = i + 1
Wend
TextBox2.Value = " AC000" & i
End Sub