probleme de macro en vba

ZinebSa

XLDnaute Nouveau
BJR, j'ai un petit souci je veux coder une macro qui cherche sur une colonne si il est ecrit sur la case non confirmé si c'est le cas elle recherche la case d'apres si elle est confirmé on doit créer un tableau sur la deuxieme feuille qui affiche les lignes de ces cas
VB:
Dim i As Integer
i = 4
Do Until Range("B4").End(xlDown).Row
If Range("B" & i).Value = Range("B" & i + 1).Value Then
If (Range("N" & i) = "IMPR LANC" Or Range("N" & i) = "CNFP CCOA IMPR LANC" Or Range("N" & i) = "CNFP IMPR LANC") And (Range("N" & i + 1) = "CONF IMPR LANC" Or Range("N" & i + 1).Value = "CONF CCOA IMPR LANC" Or Range("N" & i + 1) = "CONF IMPR LANC RECT") Then
'je ne sais pas quoi ecrire
i=i+1
End If
End If
Loop
j"ai fait un petit code et j'ai besoin d'aide pour le finir
 

ZinebSa

XLDnaute Nouveau
Salut ZinebSa,

Je ne comprends pas ta demande tu peux ajouter un classeur (sans données confidentielles) avec le résultat souhaité ?
Salut max.lander,
non je veux faire un tri sur une colonne If (Range("N" & i) = "IMPR LANC"Or Range("N" & i) = "CNFP CCOA IMPR LANC"Or Range("N" & i) = "CNFP IMPR LANC") And (Range("N" & i + 1) = "CONF IMPR LANC"Or Range("N" & i + 1).Value = "CONF CCOA IMPR LANC"Or Range("N" & i + 1) = "CONF IMPR LANC RECT")
il faut créer un tableau dans une nouvelle feuille et y mettre la ligne qui contient Range("N",&i)
 

max.lander

XLDnaute Occasionnel
Sans fichier c'est plus compliqué ,

voilà ce que je te propose en espérant que cela règle ton problème.
Le code doit être adapté à ton classeur (non feuille...)


VB:
Sub Copy_L()
Dim i, derlinge As Integer
derligne = Sheets("Feuil1").Range("B" & Rows.Count).End(xlUp).Row
For i = 4 To derligne

If Range("B" & i).Value = Range("B" & i + 1).Value Then
           If (Range("N" & i) = "IMPR LANC" Or Range("N" & i) = "CNFP CCOA IMPR LANC" Or Range("N" & i) = "CNFP IMPR LANC") And (Range("N" & i + 1) = "CONF IMPR LANC" Or Range("N" & i + 1).Value = "CONF CCOA IMPR LANC" Or Range("N" & i + 1) = "CONF IMPR LANC RECT") Then

 Sheets("Feuil2").Range("a1:n" & i).Value = Sheets("Feuil1").Range("a1:n" & i).Value
 
     End If
                End If

                                     Next i
End Sub
 

ZinebSa

XLDnaute Nouveau
Sans fichier c'est plus compliqué ,

voilà ce que je te propose en espérant que cela règle ton problème.
Le code doit être adapté à ton classeur (non feuille...)


VB:
Sub Copy_L()
Dim i, derlinge As Integer
derligne = Sheets("Feuil1").Range("B" & Rows.Count).End(xlUp).Row
For i = 4 To derligne

If Range("B" & i).Value = Range("B" & i + 1).Value Then
           If (Range("N" & i) = "IMPR LANC" Or Range("N" & i) = "CNFP CCOA IMPR LANC" Or Range("N" & i) = "CNFP IMPR LANC") And (Range("N" & i + 1) = "CONF IMPR LANC" Or Range("N" & i + 1).Value = "CONF CCOA IMPR LANC" Or Range("N" & i + 1) = "CONF IMPR LANC RECT") Then

Sheets("Feuil2").Range("a1:n" & i).Value = Sheets("Feuil1").Range("a1:n" & i).Value

     End If
                End If

                                     Next i
End Sub
Mercii max.lander,
mais le problème c'est qu'elle recopie tout le tableau nn seulement les cas que j'avais cité
 

Paf

XLDnaute Barbatruc
Bonjour Zinebsa, max.lander,

un essai à tester et adapter
Etant donné le volume de données à traiter, on passe par un tableau, plus rapide que les multiples accès cellules.
VB:
Sub Copy_L()
Dim i As Long, j As Long, derlinge As Integer, WS1 As Worksheet, WS2 As Worksheet, Tablo, x As Long
Set WS1 = Worksheets("Fichier COOIS") ' à adapter
Set WS2 = Worksheets("Feuil2")      ' à adapter
x = 1
With WS1
Tablo = .Range("B2:S" & .Range("B" & Rows.Count).End(xlUp).Row)
For i = 3 To UBound(Tablo) - 1
        If Tablo(i, 13) = "IMPR LANC" Or Tablo(i, 13) = "CNFP CCOA IMPR LANC" Or Tablo(i, 13) = "CNFP IMPR LANC" Then
            If Tablo(i + 1, 13) = "CONF IMPR LANC" Or Tablo(i + 1, 13) = "CONF CCOA IMPR LANC" Or Tablo(i + 1, 13) = "CONF IMPR LANC RECT" Then
                x = x + 1
                For j = 1 To 18
                    Tablo(x, j) = Tablo(i, j)
                Next
            End If
        End If
Next i
End With
WS2.Range("B1").Resize(x, 18) = Tablo
End Sub

A+

Edit : Bonjour gosselien ! Pas pu ouvrir ton classeur.
 
Dernière édition:

ZinebSa

XLDnaute Nouveau
Bonjour,
je vous remercie infiniment et je suis vraiment désolé j'ai pas vu vos repenses hier j'avais quelques soucis.
j'ai fait un essais ça marche mais j'ai un petit problème pouvez-vous m'aider

VB:
Dim i, j As Integer

For i = 4 To Range("B4").End(xlDown).Row

  If Range("B" & i) = Range("B" & i + 1) Then

    If Range("N" & i) = "CONF IMPR LANC" Then
  
    'MsgBox "la ligne " & i & " est confirmée"
  
      If Range("N" & i + 1) = "IMPR LANC" Then
    
      'MsgBox "la ligne " & i + 1 & " est confirmée"
    
              j = 1
            
              While Range("N" & i + j) <> "CONF IMPR LANC" And Range("N" & i + j) <> ""
            
                j = j + 1
          
                MsgBox "la ligne " & i + j - 1 & " est non-Confirmée"
            
                Sheets("Feuil1").Range("B" & i + j - 1).Copy Sheets("Feuil2").Cells(Rows.Count, 2).End(xlUp)(2)
                Sheets("Feuil1").Range("C" & i + j - 1).Copy Sheets("Feuil2").Cells(Rows.Count, 3).End(xlUp)(2)
                Sheets("Feuil1").Range("D" & i + j - 1).Copy Sheets("Feuil2").Cells(Rows.Count, 4).End(xlUp)(2)
                Sheets("Feuil1").Range("N" & i + j - 1).Copy Sheets("Feuil2").Cells(Rows.Count, 5).End(xlUp)(2)
            
              Wend
    
      End If
  
    End If

  End If

Next i

le fichier si dessus et une toute petite partie du fichier dont je test avec ...
mon probleme ici est que meme si j'ai fais la boucle tantque il l'ignore et me donne le cas qui n'ont pas de CONF aprés
 

Pièces jointes

  • Test.xlsx
    13.9 KB · Affichages: 38

ZinebSa

XLDnaute Nouveau
Re,

Visiblement nos propositions ne vous ont pas inspiré.

Difficile de répondre puisqu'on découvre ce que vous voulez faire au travers d'un code qui ne fonctionne pas selon vos besoins !!

A+

Désolé, mais j'ai pas bien compris ce que vous voulez dire?
je sais que je ne sais pas comment expliquer ma situation et mes besoins je suis nul en vba et je ne sais pas quoi faire svp essayez de m'aider je suis perdu
 

Discussions similaires

Réponses
6
Affichages
240

Statistiques des forums

Discussions
312 203
Messages
2 086 196
Membres
103 153
dernier inscrit
SamirN