Bonjour
J’ai des opérations à effectuer sur des macros suite à une fusion de fichiers et à une modification de l’emplacement du tableau.
Mon problème, c’est que je débute dans Excel et le Vba, et que j’ai encore du mal à comprendre les macros d’origine.
Voici le code source
Je dois modifier les appels sur 3 parties
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 Sub Distrib_WC() ' ' Distrib_WC Macro 'Copie de fichier Base avant L1 WC ChDir _ "P:\###########\Base WC" Workbooks.Open Filename:= _ " P:\############\Base WC\ ANALYSE DU MIX PAR FAMILLE DE WC\BASE AVANT.xls" _ , UpdateLinks:=3 Sheets(1).Copy After:=Workbooks( _ NomFichierWCJour). _ Sheets(1) Windows("BASE AVANT .xls").Activate Application.DisplayAlerts = False ActiveWindow.Close Application.DisplayAlerts = True Sheets(2).Name = "Base Avant " Range("A1").Select NbrLigneBaseAvL1 = ActiveCell.SpecialCells(xlLastCell).Row 'Suppr colonne inutile Columns("C:S").Select Range("C:S,W:AH").Select Selection.Delete Shift:=xlToLeft Columns("A:E").Select Selection.Columns.AutoFit Rows("2:2").Select ActiveWindow.FreezePanes = True Range("A1:E1").Select Selection.AutoFilter Range("A1").Select 'Application formule Sheets(NomFeuilleDonneesRequi).Select Range("A1").Select NbrLigneRequi = ActiveCell.SpecialCells(xlLastCell).Row Range("G2").Select ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3],'Base Avant '!R2C1:R1000C5,3,FALSE)" Range("H2").Select ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-4],'Base Avant '!R2C1:R1000C5,5,FALSE)" Range("G2:H2").Select Selection.AutoFill Destination:=Range("G2:H" & NbrLigneRequi) Range("G1").Select ActiveCell.FormulaR1C1 = "Type WC" With ActiveCell.Characters(Start:=1, Length:=7).Font .Name = "Arial" .FontStyle = "Gras" .Size = 10 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Range("H1").Select ActiveCell.FormulaR1C1 = "WC" With ActiveCell.Characters(Start:=1, Length:=2).Font .Name = "Arial" .FontStyle = "Gras" .Size = 10 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Range("A1:J1").Select Selection.AutoFilter Selection.AutoFilter Range("G:G,H:H").EntireColumn.AutoFit Sheets(2).Select ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _ , AllowFiltering:=True Range("A2").Select Sheets(3).Select ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _ , AllowFiltering:=True Range("A2").Select End Sub
1) Changement du nom de fichier sur lequel je travaille
2) Appel sur une feuille du classeur spécifique
3) Changement de l’emplacement de la requête (3 lignes plus bas car insertion d’un tableau en haut de feuille)
Je cherche à modifier les appels pour ne plus faire appel à base avant mais un autre fichier qui s’appelle base WC où les données sont sur une feuille spécifique (feuille abc)
Je pensais rajouter une ligne du type Sheets("abc").Select
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 'Copie de fichier Base avant L1 WC ChDir _ "P:\###########\Base WC" Workbooks.Open Filename:= _ " P:\############\Base WC\ ANALYSE DU MIX PAR FAMILLE DE WC\BASE AVANT.xls" _ Sheets("abc").Select , UpdateLinks:=3
Ainsi qu’effectuer une modification sur le chemin d’accès
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 ChDir _ "P:\###########\Base WC" Workbooks.Open Filename:= _ " P:\############\Base WC\ ANALYSE DU MIX PAR FAMILLE DE WC\BASE WC.xls" _ Sheets(1) Windows("BASE WC .xls").Activate Application.DisplayAlerts = False ActiveWindow.Close Application.DisplayAlerts = True Sheets(2).Name = "Base WC " Range("A1").Select NbrLigneBaseAvL1 = ActiveCell.SpecialCells(xlLastCell).Row 'Application formule Sheets(NomFeuilleDonneesRequi).Select Range("A1").Select NbrLigneRequi = ActiveCell.SpecialCells(xlLastCell).Row Range("G2").Select ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3],'Base WC '!R2C1:R1000C5,3,FALSE)" Range("H2").Select ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-4],'Base WC '!R2C1:R1000C5,5,FALSE)" Range("G2:H2").Select Selection.AutoFill Destination:=Range("G2:H" & NbrLigneRequi) Range("G1").Select ActiveCell.FormulaR1C1 = "Type WC" With ActiveCell.Characters(Start:=1, Length:=7).Font
Par la suite, faut il que je modifie les requêtes du Vlookup pour prendre en compte l’insertion de 3 lignes en haut du classeur ?
Comment fonctionne le?
Code : Sélectionner tout - Visualiser dans une fenêtre à part ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3],'Base WC '!R2C1:R1000C5,3,FALSE)"
Partager