Regrouper deux macro en une!!!

nonossov Messages postés 638 Statut Membre -  
Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

je cherche a regrouper deux macros,
premieure c'est:

[/contents/446-fichier-sub Sub] Fusion_col()
'
' Macro1 Macro
'
Dim Col2 As String
Dim Col1 As String
Dim Separateur As String
Dim Vide As Long
Dim i As Single
Dim c As Range

Col1 = VBA.InputBox("Quelle est la lettre de la première colone?", "Colonne 1")
Col2 = VBA.InputBox("Quelle est la lettre de la deuxième colonne ?", "Colonne 2")
Separateur = VBA.InputBox("Quel séparateur voulez vous utiliser?", "Separateur")
'Col1 = Col1 + 0

Col1 = Col1 & ":" & Col1
'Col2 = Col2 & ":" & Col2

i = 1 'Numeros de col
Vide = 0  'limite de vide 100

Dim Temp As String
For Each c In ActiveSheet.Range(Col1).Cells
    If c.Text = "" Then
        'cellule vide
    Else
        Range(Col2 & i) = c.Text & Separateur & Range(Col2 & i).Text
    End If
    i = i + 1
    
Next

'MsgBox (vide)

    
'suppression de la colonne 1
Columns(Col1).Delete Shift:=xlToLeft
End Sub


La deuxieme:
Sub NETTOYAGE()
If MsgBox("Etes-vous sur de vouloir nettoyer le journal?", vbOKCancel) = vbCancel Then
    End
End If
   

 Dim sh As Worksheet
Dim ws As Worksheet
Dim a As Long
Dim b As Long

Set ws = Sheets("Input")
Set sh = Sheets("Output")

b = ws.Range("A1").End(xlDown).Row
c = sh.Range("A1").End(xlDown).Row
sh.Activate
sh.Range("A2", Cells(c, "I")).Clear
'sh.Range("A2", Cells(c, "I")).Interior.Color = RGB(255, 255, 255)
For a = 2 To b
sh.Cells(a, "C") = ws.Cells(a, "C")
sh.Cells(a, "A") = ws.Cells(a, "G")
sh.Cells(a, "E") = ws.Cells(a, "I")
sh.Cells(a, "B") = ws.Cells(a, "L")
sh.Cells(a, "G") = ws.Cells(a, "M")
sh.Cells(a, "D") = ws.Cells(a, "X")


Next
sh.Range("A2", Cells(b, "A")).NumberFormat = "dd/mm/yyyy;@"

Dim maplageC As Range

Set maplageC = sh.Range("G2", Cells(b, "G"))

For Each cellule In maplageC
  If cellule.Value > 0 Then
     sh.Cells(cellule.Row, 6).Value = "C"
  Else
    sh.Cells(cellule.Row, 6).Value = "D"
    
    End If

Next


Range("H2").Select
ActiveCell.FormulaR1C1 = "=MID(RC[-4],SEARCH("".TIF"",RC[-4])-8,8)"
Selection.Copy
Range("G60000").End(xlUp).Offset(0, 1).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("D2").Select
ActiveCell.FormulaR1C1 = "=RC[4]"
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Columns("H:H").ClearContents
Columns("D:D").EntireColumn.AutoFit
Range("A2").Select


Columns("A:G").Select
Selection.AutoFilter
ActiveSheet.Range("$A:$G").AutoFilter Field:=7, Criteria1:=">0", Operator:=xlAnd
Range("G60000").End(xlUp).Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=RC[-1]"
Selection.Copy
Range(Selection, Range("H2")).Select
ActiveSheet.Paste
Selection.AutoFilter

Columns("H:H").Copy
Range("H1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

ActiveSheet.Range("$A:$H").AutoFilter Field:=7, Criteria1:=">0", Operator:=xlAnd
        
Columns("G:G").SpecialCells(xlCellTypeVisible).ClearContents
Selection.AutoFilter






End Sub
    
    
    
    
Sub test()

Columns("A:G").Select
Selection.AutoFilter
ActiveSheet.Range("$A:$G").AutoFilter Field:=7, Criteria1:=">0", Operator:=xlAnd
Range("G60000").End(xlUp).Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=RC[-1]"
Selection.Copy
Range(Selection, Range("H2")).Select
ActiveSheet.Paste
Selection.AutoFilter

Columns("H:H").Copy
Range("H1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

ActiveSheet.Range("$A:$H").AutoFilter Field:=7, Criteria1:=">0", Operator:=xlAnd
        
Columns("G:G").SpecialCells(xlCellTypeVisible).ClearContents
Selection.AutoFilter



End Sub




Merci infiniment

1 réponse

  1. Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   1 783
     
    NB : Quand tu postes du code sur le forum, utiliser les balises c'est bien,
    mais avec indication du langage (=coloration syntaxique) c'est mieux
    Explications disponibles ici : Comment utiliser les balises de code
    Exemple :
    Sub UtiliserLesBalises()
      MsgBox "Merci d'utiliser les balises de code"
    End Sub

    1
    1. nonossov Messages postés 638 Statut Membre
       
      C bon mtn? Merci de m'aider sur cette macro?
      0
    2. nonossov Messages postés 638 Statut Membre
       
      je pense que la macro est claire!
      0
    3. Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   1 783
       
      La première ça va, mais sans fichier, la seconde n'est facile à mettre en œuvre :

      Pour la première j'aurais écrit :
      Option Explicit
      Sub Fusion_col()
      Dim Col2 As String
      Dim Col1 As String
      Dim sep As String
      Dim r As Range
      Dim c As Range
        Col1 = VBA.InputBox("Quelle est la lettre de la première colone?", "Colonne 1")
        Col2 = VBA.InputBox("Quelle est la lettre de la deuxième colonne ?", "Colonne 2")
        sep = VBA.InputBox("Quel séparateur voulez vous utiliser?", "Separateur")
        With ActiveSheet
          Set r = Intersect(.Columns(Col2), .UsedRange)
          For Each c In r.Cells
            If c.Text <> "" Or .Cells(c.Row, Col1).Text <> "" Then
              'fusion des infos
              c.Text = .Cells(c.Row, Col1).Text & sep & c.Text
            End If
          Next c
        End With
        'suppression de la colonne 1
        Columns(Col1).Delete Shift:=xlToLeft
      End Sub


      Ce qui n'est pas clair, c'est « je cherche a regrouper deux macros »
      Ces macros sont indépendantes, qu'entends tu par regrouper ?
      0
    4. nonossov Messages postés 638 Statut Membre
       
      le probleme que je vouderai mettre ces deux macro dans une seule macro
      0
    5. Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   1 783
       
      il suffit d'ajouter au début (ou à la fin selon ce que te veux) de ta première macro :
      Call NETTOYAGE
      0