Probleme de macro

Probleme de macro - VB/VBA/VBS - Programmation

Marsh Posté le 11-03-2015 à 19:56:05    

Bonsoir à tous,  
débutante en VBA, je viens de m'inscrire sur ce site en espérant trouver quelques réponses à mon problème :)
 
Je vous explique le contexte:
j'ai deux fichiers: un fichier source dans lequel j'ai de nombreuses données et un second dans lequel je récupere certaines donnée (je l'apellerais fichier target) du dossier source.
je souhaite quand une condition est remplis dans une colonne copier certaines valeur de la ligne correspondante dans mon second fichier. je veux que ce copier/coller ce réalise tant que la condition est vrai.
 
avant de réaliser cela je demande par une macro qu'elle aye chercher mon dossier source et qu'elle enregistre le fichier target par un nom.
 
je souhaiterais également que toutes mes macros s'exécute ensemble.
 
je vous copie ma macro dessous.
Est ce que quelqu'un pourrais me dire où j'ai fait une erreur car j'ai erreur 91 et erreurs de compliation et je ne sais pas où j'ai "merdé"
merci d'avance
 
 
 
Public wbSource As Workbook
Public wbTarget As Workbook
 
Sub main()
 
Dim stFileName As String
 
stFileName = Application.GetOpenFilename
If stFileName <> "False" Then
    Workbooks.Open stFileName
    stFileName = Right(stFileName, Len(stFileName) - InStrRev(stFileName, "\" ))
     
    Set wbSource = Workbooks(stFileName)
    Set wbTarget = ThisWorkbook
     
    wbTarget.Activate
    Application.Dialogs(xlDialogSaveAs).Show ("Beam KPIs Week " & Format(Date, "ww", vbMonday, vbFirstFourDays))
 
End If
 
End Sub
 
Sub Acceptance()
   
Dim i As Integer
Dim j As Integer
Dim k As Integer
 
Dim wbSource As Workbooks
Dim wbTarget As Workbooks
Dim QG_Tracker As Worksheets
Dim Acceptance_status_W As Worksheets
 
 
i = 4
j = 3
k = 3
 
 
While (wbSource.Worksheets("QG_Tracker" ).Cells(i, 2).Value <> "" )
    If wbSource.Worksheets("QG_Tracker" ).Cells(i, 15).Value <= Date And wbSource.Worksheets("QG_Tracker" ).Cells(i, 15).Value >= (Date - 6) Then
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 1).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 2).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 2).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 3).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 3).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 5).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 4).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 7).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 5).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 8).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 6).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 11).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 7).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 15).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 8).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 16).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 9).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 30).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 10).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 29).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 11).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 31).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 12).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 32).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 13).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 33).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 14).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 34).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 15).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 35).Value
        wbTarget.Worksheets("Acceptance status W" ).Cells(j, 16).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 36).Value
        j = j + 1
    End If
    If wbSource.Worksheets("QG_Tracker" ).Cells(i, 15).Value > Date And wbSource.Worksheets("QG_Tracker" ).Cells(i, 15).Value <= (Date + 7) Then
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 1).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 2).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 2).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 3).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 3).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 5).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 4).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 7).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 5).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 8).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 6).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 11).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 7).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 15).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 8).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 30).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 9).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 29).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 10).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 31).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 11).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 32).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 12).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 33).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 13).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 34).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 14).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 35).Value
        wbTarget.Worksheets("Acceptance planned W" ).Cells(k, 15).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 36).Value
        k = k + 1
    End If
    i = i + 1
 
Wend
 
End Sub
 
 
 
 
Sub Agreement()
   
Dim i As Integer
Dim j As Integer
Dim k As Integer
 
i = 4
j = 3
k = 3
 
While (wbSource.Worksheets("QG_Tracker" ).Cells(i, 2).Value <> "" )
    If wbSource.Worksheets("QG_Tracker" ).Cells(i, 13).Value <= Date And wbSource.Worksheets("QG_Tracker" ).Cells(i, 13).Value >= (Date - 6) Then
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 1).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 2).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 2).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 3).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 3).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 5).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 4).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 7).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 5).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 8).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 6).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 11).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 7).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 13).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 8).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 30).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 9).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 29).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 10).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 31).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 11).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 32).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 12).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 33).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 13).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 34).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 14).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 35).Value
        wbTarget.Worksheets("Agreement status W" ).Cells(j, 15).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 36).Value
        j = j + 1
    End If
    If wbSource.Worksheets("QG_Tracker" ).Cells(i, 13).Value > Date And wbSource.Worksheets("QG_Tracker" ).Cells(i, 13).Value <= (Date + 7) Then
        wbTarget.Worksheets("Agreement planned W" ).Cells(k, 1).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 2).Value
        wbTarget.Worksheets("Agreement planned W" ).Cells(k, 2).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 3).Value
        wbTarget.Worksheets("Agreement planned W" ).Cells(k, 3).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 5).Value
        wbTarget.Worksheets("Agreement planned W" ).Cells(k, 4).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 7).Value
        wbTarget.Worksheets("Agreement planned W" ).Cells(k, 5).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 8).Value
        wbTarget.Worksheets("Agreement planned W" ).Cells(k, 6).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 11).Value
        wbTarget.Worksheets("Agreement planned W" ).Cells(k, 7).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 13).Value
        k = k + 1
    End If
    i = i + 1
 
Wend
 
End Sub
 
Sub CSF()
 
Dim i As Integer
Dim j As Integer
 
i = 4
j = 3
 
While (wbSource.Worksheets("QG_Tracker" ).Cells(i, 2).Value <> "" )
    If wbSource.Worksheets("QG_Tracker" ).Cells(i, 29).Value = "CSF not fulfilled" And wbSource.Worksheets("QG_Tracker" ).Cells(i, 16).Value = " Not yet happened " Then
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 1).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 2).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 2).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 3).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 3).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 5).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 4).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 7).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 5).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 8).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 6).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 11).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 7).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 13).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 8).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 30).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 9).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 29).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 10).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 31).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 11).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 32).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 12).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 33).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 13).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 34).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 14).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 35).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 15).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 36).Value
        j = j + 1
    End If
    If wbSource.Worksheets("QG_Tracker" ).Cells(i, 29).Value = "" And wbSource.Worksheets("QG_Tracker" ).Cells(i, 21).Value = "CSF not fulfilled" And wbSource.Worksheets("QG_Tracker" ).Cells(i, 16).Value = "In progress" Then
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 1).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 2).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 2).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 3).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 3).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 5).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 4).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 7).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 5).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 8).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 6).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 11).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 7).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 13).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 8).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 30).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 9).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 29).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 10).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 31).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 11).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 32).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 12).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 33).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 13).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 34).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 14).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 35).Value
        wbTarget.Worksheets("CSF not fulfilled" ).Cells(j, 15).Value = wbSource.Worksheets("QG_Tracker" ).Cells(i, 36).Value
        j = j + 1
    End If
    i = i + 1
Wend
 
End Sub
 
 
merci de votre aide,
Bonne soirée

Reply

Marsh Posté le 11-03-2015 à 19:56:05   

Reply

Marsh Posté le 12-03-2015 à 19:09:30    

 
           Bonjour, bonjour !
 
           Commencer par lire les règles du forum afin de les respecter …
 
           Sinon copier des données d'une feuille de calculs selon une condition vers une autre feuille ne réclame pas dix lignes de code ‼
           Et ce en une seule passe sans boucle ! …
 
           S'entraîner en l'effectuant manuellement via un filtre avancé (B-A-BA d'Excel, consulter son aide) puis une fois aguerri,
           activer le Générateur de macros avant de la reproduire une nouvelle fois : une base de code est livrée sur un plateau !
 
           Astuce :  lorsque la destination du résultat d'un filtre avancé n'est pas la feuille source, se placer sur la feuille destination pour débuter …
 

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed