Macro compatible tout xls
bonjour tout le monde
Je reviens avec une nouvelle formulation car il me semble que j'ai pas été clair lors de la premiére , je veux eviter de faire du copier coller des données avant de les traiter avec ma macro.
j'ai enregistré la macro sur le ruban mais elle ne fonctionne qu'avec le .xls sous lequel j'enregistre !!
est ce que je peux faire en sorte qu'elle fonctionne un n'importe qu'elle xls que j'ouvre ?
c'est surtout les lignes qui ne s'exécute pas!!!
Code:
1 2
| Code = .Cells(Val.Row, 2).Value
ThisWorkbook.Range("C" & ligne) = Code |
merci
Code:
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| Sub MEF()
Dim CIBLE, Code As Variant
Dim ligne As Integer
Dim Val As Range
Worksheets(1).Columns("C:C").Insert Shift:=xlToRight
Worksheets(1).Columns("N:N").Insert Shift:=xlToRight
ThisWorkbook.Worksheets(1).Cells(1, 3) = "ARTICLE "
ThisWorkbook.Worksheets(1).Cells(1, 13) = "DATE"
For ligne = 2 To Range("A" & Rows.Count).End(xlUp).Row
If (IsEmpty(Range("A" & ligne))) Then
'MsgBox "Code Article Manquant à la ligne " & ligne
Exit Sub
Else
CIBLE = Range("A" & ligne)
Range("M" & ligne) = Left(Range("M" & ligne).Value, 9)
If Split(UCase(Range("O" & ligne).Value), "/")(1) = "M" Then
Range("L" & ligne).Value = Range("L" & ligne).Value / 1000
End If
Range("N" & ligne).Value = Format(Range("M" & ligne).Value, "yyyymm")
Feuil1.Range("K" & ligne).NumberFormat = "###0"
'MsgBox "Code Article " & CIBLE & " recherche"
Call Find(CIBLE, Code, ligne)
End If
Next ligne
End Sub
Sub Find(CIBLE, Code, ligne)
Dim x As Variant
Dim Val As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wbk = Workbooks.Open("U:\redirection\reférence.xlsx")
With wbk.Worksheets("Feuil1")
Set Val = .Columns("A:A").Find(CIBLE, LookIn:=xlValues)
If Not Val Is Nothing Then
'MsgBox "Le Code Article" & CIBLE & "est dans la ligne: " & Val.Row
Code = .Cells(Val.Row, 2).Value
ThisWorkbook.Range("C" & ligne) = Code
Else
'MsgBox "Code Article " & CIBLE & " non trouvée dans la table de correspondance"
End If
End With
wbk.Save
wbk.Close
Set wbk = Nothing
Application.ScreenUpdating = True
End Sub |