Bonjour a Tous,
Je viens a tous pour un hic rencontre dans mon code vba.
La logique de mon fichier excel etait de me permettre de trouver l'emplacement(positionnement) de mes marchandises dans les differents magasins.
Pour Effectuer la recherche j'utilise un userform et a l'aide d'un code vba je dois retrouver la merchandise rechercher.
La merchandise rechercher se differentie par une couleur verte lorsqu'on la trouve.
Les 4 magasins s'etendent de la colonne B a colonne BK et de la ligne 5 a la ligne 42.
la recherche se fait comme suit (voir ecran) , le numero de lot est renseigner dans l'userform pour retrouver sa position dans le magasin.
A la suite un userform s'affiche ou l'utilisateur devra cliquer sur "voir plan" pour voir la position virtuel de la marchandise dans le magasin qui sera colore maintenant a la suite mon probleme arrive lorsqu'une autre recherche est faite a nouveau la preccedente position coloree reste toujours verte y compris la nouvelle position la merchandise recherche , au lieu de colore uniquement la position exacte ou se trouve la nouvelle recherche ou souvent il colore plusieurs positions.(Voir image)
Ci-dessous les images
Merci voir mes differents code VBA
Code VBA pour userform pour les boutons commande1"voir sur plan" et commande2"fermer".
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Private Sub CommandButton1_Click() ThisWorkbook.Sheets(1).Activate Dim lign As Integer, col As Integer For ligne = 5 To 42 For col = 2 To 65 If Len(Cells(ligne, col)) = 3 Or Len(Cells(ligne, col)) = 5 Then Cells(ligne, col).Interior.ColorIndex = 24 End If If Cells(ligne, col).Value = UserForm1.Label6.Caption Then Cells(ligne, col).Interior.ColorIndex = 4 End If Next col Next ligne End Sub Private Sub CommandButton2_Click() Dim lign As Integer, col As Integer For ligne = 5 To 42 For col = 2 To 65 If Len(Cells(ligne, col)) = 3 Or Len(Cells(ligne, col)) = 5 Then Cells(ligne, col).Interior.ColorIndex = 24 End If Next col Next ligne Unload UserForm1 ThisWorkbook.Sheets(2).Activate End Sub
Code vba pour la feuille "recherche"
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 Private Sub Worksheet_Activate() Dim reference As String, verif As String reference = InputBox("saisissez une reference:", "rechercher une reference") verif = "" Dim i As Integer i = 2 Do While Sheets("recherche").Cells(i, 1) <> "" If Sheets("recherche").Cells(i, 1) Like reference Then UserForm1.Label11.Caption = Sheets("recherche").Cells(i, 1).Value UserForm1.Label2.Caption = Sheets("recherche").Cells(i, 2).Value UserForm1.Label5.Caption = Sheets("recherche").Cells(i, 3).Value UserForm1.Label6.Caption = Sheets("recherche").Cells(i, 4).Value UserForm1.Label7.Caption = Sheets("recherche").Cells(i, 5).Value verif = "ok" UserForm1.Show End If i = i + 1 Loop If verif <> "ok" Then MsgBox "reference invalide..." End If End Sub
Plan des Entrepots.zip
Partager