Modifier doublon sous condition

Résolu/Fermé
Leghe59 Messages postés 34 Date d'inscription mercredi 14 juin 2017 Statut Membre Dernière intervention 17 avril 2021 - Modifié le 18 mai 2018 à 17:20
Leghe59 Messages postés 34 Date d'inscription mercredi 14 juin 2017 Statut Membre Dernière intervention 17 avril 2021 - 19 mai 2018 à 09:48
Bonjour,

Je bloque sur la macro suivante :
- Classeur :
ISBN DISPO FOURNISSEUR
3281553413593 non dispo LIBRISOFT
3282118102310 dispo CRAENEN
3282118102310 non dispo LIBRISOFT
- Objectif :
SI ISBN = doublon
SI FOURNISSEUR = "CRAENEN" ET DISPO = "dispo"
ALORS FOURNISSEUR "LIBRISOFT" DISPO = "DISPONIBLE"

Donc :
ISBN DISPO FOURNISSEUR
3281553413593 non dispo LIBRISOFT
3282118102310 dispo CRAENEN
3282118102310 DISPONIBLE LIBRISOFT

Ma macro :
Sub nouveautes()
Dim ISBN As Range
Dim dl As Long
Dim x As Long
Dim y As Long
Dim Fournisseur As Range
Dim Dispo As Range
Set ISBN = Range("A2:A" & Range("A2").End(xlDown).Row)
Set Fournisseur = Range("C2:C" & Range("C2").End(xlDown).Row)
Set Dispo = Range("B2:B" & Range("B2").End(xlDown).Row)
ISBN.CurrentRegion.Sort Key1:=ISBN, Order1:=xlAscending, Header:=xlYes
dl = Cells(Application.Rows.Count, 1).End(xlUp).Row
For x = dl to 2 step - 1
y = x - 1
If Application.WorksheetFunction.CountIf(Range("A2:A" & dl), Cells(x, 1)) > 1 Then
If UCase(Dispo.Cells(x).Value) Like "dispo" Then Dispo.Cells(y).Value = "DISPONIBLE"
End If
Next x
End Sub


Où est mon erreur ?

Merci à tou(te)s !
A voir également:

4 réponses

yg_be Messages postés 22707 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 avril 2024 1 471
18 mai 2018 à 19:05
bonjour, quel est le symptôme: message d'erreur, résultat inattendu, ?
0
Leghe59 Messages postés 34 Date d'inscription mercredi 14 juin 2017 Statut Membre Dernière intervention 17 avril 2021
18 mai 2018 à 19:07
Et bien rien, il ne se passe rien après le tri..............
0
yg_be Messages postés 22707 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 avril 2024 1 471
18 mai 2018 à 19:30
une erreur simple:
UCase(Dispo.Cells(x).Value) Like "dispo"

serait mieux ainsi:
UCase(Dispo.Cells(x).Value) = "DISPO"


une autre erreur:
au lieu de faire
 dispo.Cells(x).Value
, ce serait plus correct de faire
Cells(x,2).Value
0
yg_be Messages postés 22707 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 avril 2024 1 471
18 mai 2018 à 19:36
cela nous conduit à ceci:
Option Explicit

Sub nouveautes()
Dim ISBN As Range
Dim dl As Long
Dim x As Long
Set ISBN = Range("A2:A" & Range("A2").End(xlDown).Row)
ISBN.CurrentRegion.Sort Key1:=ISBN, Order1:=xlAscending, Header:=xlYes
dl = Cells(Application.Rows.count, 1).End(xlUp).Row
For x = dl To 2 Step -1
    If Application.WorksheetFunction.CountIf(ISBN, Cells(x, 1)) > 1 Then
        If UCase(Cells(x, 2).Value) = "DISPO" Then
            Cells(x - 1, 2).Value = "DISPONIBLE"
        End If
    End If
Next x
End Sub

tu vas maintenant pouvoir commencer à corriger les problèmes de logique.
0
Leghe59 Messages postés 34 Date d'inscription mercredi 14 juin 2017 Statut Membre Dernière intervention 17 avril 2021
18 mai 2018 à 20:04
Merci pour tes précisions.
Cela dit, cela ne fonctionne toujours pas...
0
yg_be Messages postés 22707 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 avril 2024 1 471
18 mai 2018 à 20:43
tu vas maintenant pouvoir commencer à corriger les problèmes de logique.
réfléchis à la logique que tu appliques. peux-tu la décrire?
quand je teste avec le programme épuré, il y a quelque chose qui change dans les données: ce n'est pas le cas chez toi?
0
Leghe59 Messages postés 34 Date d'inscription mercredi 14 juin 2017 Statut Membre Dernière intervention 17 avril 2021
Modifié le 19 mai 2018 à 10:27
Argh, une nuit de sommeil et tout va mieux. J'avais zappé le UCase et mes minuscules !!!
Merci pour tout, je passe en résolu.
0