Bonjour à tous,
Je n'y connais pas grand choses en VBA et j'ai le même message d'erreur, pouriez vous peut etre m'aider ?
Si vous avez besoin du reste du code n'hésitez pas.
Voici le code de la fonction ajout client:
Dim nom As String
Dim code As String
Dim typ As String
Dim famille As String
Dim ville As String
Dim nombre As Integer
Dim num As Integer
Dim TrouveType As Boolean
Dim TrouveFam As Boolean
Dim nb As Integer
Sub CommandButton1_Click()
nombre = nbligne
TrouveType = False
TouveFam = False
nb = 0
If nomc = "" Then
rep = MsgBox("Veuillez saisir le nom !", vbOKOnly, "Attention" )
nomc.SetFocus
Exit Sub
End If
If villec = "" Then
rep = MsgBox("Veuillez saisir la ville !", vbOKOnly, "Attention" )
villec.SetFocus
Exit Sub
End If
If codec = "" Then
rep = MsgBox("Veuillez saisir le code !", vbOKOnly, "Attention" )
codec.SetFocus
Exit Sub
End If
If typec = "" Then
rep = MsgBox("Veuillez saisir le type !", vbOKOnly, "Attention" )
typec.SetFocus
Exit Sub
End If
If famillec = "" Then
rep = MsgBox("Veuillez saisir la famille !", vbOKOnly, "Attention" )
famillec.SetFocus
Exit Sub
End If
nom = Format(nomc, ">" )
code = Format(codec, ">" )
typ = Format(typec, ">" )
famille = Format(famillec, ">" )
ville = villec
For i = 12 To nombre
If Cells(i, 2).Value = "Total External Sales" Then
num = i
End If
If Cells(i, 6).Value = typ Then
TrouveType = True
End If
If Cells(i, 2).Value = famille Then
TrouveFam = True
nb = nb + 1
End If
Next i
If TrouveType = False Then
rep = MsgBox("Le type " & typ & " n'existe pas !", vbOKOnly, "Attention" )
typec.SetFocus
Exit Sub
End If
If TrouveFam = False Then
rep = MsgBox("La famille " & famille & " n'existe pas !", vbOKOnly, "Attention" )
famillec.SetFocus
Exit Sub
End If
For index = 3 To 14
ActiveWorkbook.Worksheets(index).Activate
For i = 12 To nombre
If Cells(i, 6).Value = typ Then
If Cells(i, 2).Value = famille Then
Rows(i + 1 & ":" & i + 1).Select
Selection.Insert Shift:=xlDown 'insertion d une ligne
Cells(i + 1, 2).Value = famille
Cells(i + 1, 3).Value = ville
Cells(i + 1, 4).Value = code
Cells(i + 1, 5).Value = nom
Cells(i + 1, 6).Value = typ
Range(Cells(i, 8), Cells(i, 20)).Select
Selection.Copy
Range(Cells(i + 1, 8), Cells(i + 1, 8)).Select
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Cells(i + 1, 10).Value = ""
Cells(i + 1, 12).Value = ""
Cells(i + 1, 14).Value = ""
Cells(i + 1, 17).Value = ""
Cells(i + 1, 18).Value = ""
Cells(i + 1, 19).Value = ""
Exit For
End If
End If
Next i
If nb = 1 Then 'cas ou il y avait 1 client dans la famille
Rows(i + 2 & ":" & i + 2).Select
Cells(i + 2, 7).FormulaR1C1 = "=SUBTOTAL(9,R[-2]C:R[-1]C)"
Cells(i + 2, 8).FormulaR1C1 = "=SUBTOTAL(9,R[-2]C:R[-1]C)"
Cells(i + 2, 10).FormulaR1C1 = "=SUBTOTAL(9,R[-2]C:R[-1]C)"
Cells(i + 2, 19).FormulaR1C1 = "=SUBTOTAL(9,R[-2]C:R[-1]C)"
Cells(i + 2, 12).FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)+RC[5]"
Cells(i + 2, 14).FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)+RC[4]"
Cells(i + 2, 17).FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Cells(i + 2, 18).FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
End If
Range("A1" ).Select
Next index
Dim XLFichier As Workbook
Set XLFichier = Workbooks.Open("\\ttfrvilfs01\travail\Commerci\Previsions\Roller\Forecast 2006\Sales YTD.xls" )
XLFichier.Worksheets(1).Activate
For i = 12 To nombre
If Cells(i, 6).Value = typ Then
If Cells(i, 2).Value = famille Then
Rows(i + 1 & ":" & i + 1).Select
Selection.Insert Shift:=xlDown 'insertion d une ligne
Cells(i + 1, 2).Value = famille
Cells(i + 1, 3).Value = ville
Cells(i + 1, 4).Value = code
Cells(i + 1, 5).Value = nom
Cells(i + 1, 6).Value = typ
Range(Cells(i, 8), Cells(i, 20)).Select
Selection.Copy
Range(Cells(i + 1, 8), Cells(i + 1, 8)).Select
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Cells(i + 1, 7).Value = ""
Cells(i + 1, 10).Value = ""
Cells(i + 1, 12).Value = ""
Cells(i + 1, 14).Value = ""
Cells(i + 1, 17).Value = ""
Cells(i + 1, 18).Value = ""
Cells(i + 1, 19).Value = ""
Exit For
End If
End If
Next i
If nb = 1 Then 'cas ou il y avait 1 client dans la famille
Rows(i + 2 & ":" & i + 2).Select
Cells(i + 2, 7).FormulaR1C1 = "=SUBTOTAL(9,R[-2]C:R[-1]C)"
Cells(i + 2, 8).FormulaR1C1 = "=SUBTOTAL(9,R[-2]C:R[-1]C)"
Cells(i + 2, 10).FormulaR1C1 = "=SUBTOTAL(9,R[-2]C:R[-1]C)"
Cells(i + 2, 19).FormulaR1C1 = "=SUBTOTAL(9,R[-2]C:R[-1]C)"
Cells(i + 2, 12).FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)+RC[5]"
Cells(i + 2, 14).FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)+RC[4]"
Cells(i + 2, 17).FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Cells(i + 2, 18).FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
End If
Range("A1" ).Select
XLFichier.Save
XLFichier.Close
Set XLFichier = Nothing
Application.ActiveWorkbook.Save
SaisieClient.Hide
Unload SaisieClient
End Sub
Sub CommandButton2_Click()
SaisieClient.Hide
Unload SaisieClient
Range("a1" ).Select
End Sub
Lorsque je click sur debuger ca me renvoie a cette ligne de code:
For index = 3 To 14
ActiveWorkbook.Worksheets(index).Activate For i = 12 To nombre
If Cells(i, 6).Value = typ Then
If Cells(i, 2).Value = famille Then
Rows(i + 1 & ":" & i + 1).Select
Selection.Insert Shift:=xlDown 'insertion d une ligne
Cells(i + 1, 2).Value = famille
Cells(i + 1, 3).Value = ville
Cells(i + 1, 4).Value = code
Cells(i + 1, 5).Value = nom
Cells(i + 1, 6).Value = typ
Range(Cells(i, 8), Cells(i, 20)).Select
Selection.Copy
Range(Cells(i + 1, 8), Cells(i + 1, 8)).Select
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Cells(i + 1, 10).Value = ""
Cells(i + 1, 12).Value = ""
Cells(i + 1, 14).Value = ""
Cells(i + 1, 17).Value = ""
Cells(i + 1, 18).Value = ""
Cells(i + 1, 19).Value = ""
Exit For
End If
End If
Next i
Message édité par dudul71 le 22-11-2007 à 17:21:00