Macro excel qui bloque avec un nom de feuille qui change tous les jours

Résolu/Fermé
queffelec125 Messages postés 5 Date d'inscription jeudi 10 avril 2014 Statut Membre Dernière intervention 15 novembre 2018 - 15 nov. 2018 à 13:29
Patrice33740 Messages postés 8556 Date d'inscription dimanche 13 juin 2010 Statut Membre Dernière intervention 2 mars 2023 - 22 nov. 2018 à 22:42
Bonjour,

Tous les jours, je reçois un fichier excel comportant une seule feuille. Cette feuille porte un nom différent chaque jour, par exemple : JT_SACD_PARIS_79182426_181113 puis le lendemain JT_SACD_PARIS_79182426_181114)...

Pour mettre en forme ce fichier j'ai besoin d'exécuter une macro mais comme le nom de la feuille change cela bloque la macro. Avez-vous une solution pour que ma macro fonctionne quel que soit le nom de la feuille excel ?

Merci
A voir également:

6 réponses

m@rina Messages postés 20065 Date d'inscription mardi 12 juin 2007 Statut Contributeur Dernière intervention 23 avril 2024 11 271
15 nov. 2018 à 13:34
Bonjour,

On ne connaît pas ta macro, mais bon s'il y a une seule feuille, on met le numéro de la feuille, c'est tout.
Par exemple ActiveWorkbook.Sheets(1).Select

m@rina
0
Patrice33740 Messages postés 8556 Date d'inscription dimanche 13 juin 2010 Statut Membre Dernière intervention 2 mars 2023 1 775
15 nov. 2018 à 13:38
Bonjour,

Sans le code, il est difficile de donner une réponse efficace !
Il y a différentes manières de s'affranchir du nom de la feuille, le plus simple est d'utiliser son index :
  Set MaFeuille = Workbooks("MonClasseur").Worksheets(1)


0
queffelec125 Messages postés 5 Date d'inscription jeudi 10 avril 2014 Statut Membre Dernière intervention 15 novembre 2018
15 nov. 2018 à 14:23
ma macro bloque à ce niveau :

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False<gras>
Sheets("JT_SACD_PARIS_79182426_181113 (").

Attention, je suis un amateur en macro. Voici le contenu de ma macro :

Rows("1:1").Select
Selection.Delete Shift:=xlUp
Selection.AutoFilter
ActiveSheet.Range("$A$1:$AF$41").AutoFilter Field:=13, Criteria1:="=CB", _
Operator:=xlOr, Criteria2:="=VISA"
ActiveWindow.SmallScroll ToRight:=5
ActiveSheet.Range("$A$1:$AF$41").AutoFilter Field:=20, Criteria1:= _
"CAPTURED"
Rows("3:3").Select
Range("F3").Activate
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("J4").Select
Selection.Copy
Range("J3").Select
ActiveSheet.Paste
Range("M4").Select
Application.CutCopyMode = False
Selection.Copy
Range("M3").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "CB"
Range("O4").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-7]>0,RC[-7]/100,"""")"
Range("O4").Select
Selection.Copy
Range("O5:O324").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("O3").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,RC:R[375]C)"
Range("O3").Select
Selection.ClearContents
ActiveCell.FormulaR1C1 = "=SUM(R[1]C:R[249]C)"
Range("AG1").Select
ActiveCell.FormulaR1C1 = "compte"
Range("AG3").Select
ActiveCell.FormulaR1C1 = "512206"
Range("AH1").Select
ActiveCell.FormulaR1C1 = "sens"
Range("AG4").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-25]>0,450101,"""")"
Range("AG4").Select
Selection.Copy
Range("AG5:AG184").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("AH3").Select
ActiveCell.FormulaR1C1 = "si("
Range("O3").Select
Range("AH3").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-19]>0,""C"",""D"")"
Range("AH3").Select
Selection.Copy
Range("AH4:AH218").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("AH3").Select
ActiveCell.FormulaR1C1 = "D"
Range("AH4").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-19]>0,""C"","""")"
Range("AH4").Select
Selection.Copy
Selection.End(xlDown).Select
Range("AH218:AH253").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH184").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH149").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH114").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH79").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH44").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH6").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH5:AH254").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("AH4").Select
ActiveWindow.LargeScroll ToRight:=-1
Cells.Select
Range("L1").Activate
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("JT_SACD_PARIS_79182426_181113 (").Select
ActiveSheet.Range("$A$1:$AF$324").AutoFilter Field:=13, Criteria1:="SDD"
Application.CutCopyMode = False
ActiveWindow.SmallScroll ToRight:=20
Rows("8:8").Select
Range("U8").Activate
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveWindow.ScrollColumn = 20
ActiveWindow.ScrollColumn = 19
ActiveWindow.ScrollColumn = 18
ActiveWindow.ScrollColumn = 17
ActiveWindow.ScrollColumn = 16
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Range("J9").Select
Selection.Copy
Range("J8").Select
ActiveSheet.Paste
Range("AG8").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "512206"
Range("AG9").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-25]>0,""450101"","""")"
Range("AG9").Select
Selection.Copy
Range("AG35:AG390").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("AH8").Select
ActiveCell.FormulaR1C1 = "D"
Range("AH9").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-26]>0,""C"","""")"
Range("AH9").Select
Selection.Copy
Range("AH35:AH390").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.LargeScroll ToRight:=-1
Range("M9").Select
Selection.Copy
Range("M8").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll ToRight:=-8
Range("O9").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-7]>0,RC[-7]/100,"""")"
Range("O9").Select
Selection.Copy
Range("O35:O390").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("O8").Select
Selection.FormulaR1C1 = "="
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[1]C:R[374]C)"
Range("O8").Select
ActiveWindow.SmallScroll Down:=-18
Rows("8:330").Select
Range("H8").Activate
Selection.Copy
Sheets("Feuil1").Select
ActiveWindow.SmallScroll Down:=24
Rows("39:39").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
0
m@rina Messages postés 20065 Date d'inscription mardi 12 juin 2007 Statut Contributeur Dernière intervention 23 avril 2024 11 271
15 nov. 2018 à 15:26
ça mérite un bon nettoyage ! :s
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 728
15 nov. 2018 à 15:09
Bonjour,

As-tu lu les réponses de marina et Patrice?

Voici un peu de lecture pour affranchir le nom de la feuille

https://silkyroad.developpez.com/VBA/FeuilleDeCalcul/

0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
queffelec125 Messages postés 5 Date d'inscription jeudi 10 avril 2014 Statut Membre Dernière intervention 15 novembre 2018
15 nov. 2018 à 15:44
Merci à tous pour vos réponses.

N'étant pas informaticien je construis mes macros de la manière suivante :

En fait, je n'écris pas la macro, mais elle enregistre mes actions c'est pourquoi il y a certainement du nettoyage à faire.

Mais mon problème demeure, les différentes réponses ne me permettent pas de lancer ma macro.

Mon problème apparait à ce niveau :

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("JT_SACD_PARIS_79182426_181113 (").Select


Par quoi faut-il remplacer "JT_SACD_PARIS_79182426_181113" pour que la macro ne se bloque pas chaque jour alors que le nom de la feuille est chaque jour différent ?


Je remets ci-dessous ma macro et si quelqu'un peut m'aider, d'avance merci :

Rows("1:1").Select
Selection.Delete Shift:=xlUp
Selection.AutoFilter
ActiveSheet.Range("$A$1:$AF$41").AutoFilter Field:=13, Criteria1:="=CB", _
Operator:=xlOr, Criteria2:="=VISA"
ActiveWindow.SmallScroll ToRight:=5
ActiveSheet.Range("$A$1:$AF$41").AutoFilter Field:=20, Criteria1:= _
"CAPTURED"
Rows("3:3").Select
Range("F3").Activate
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("J4").Select
Selection.Copy
Range("J3").Select
ActiveSheet.Paste
Range("M4").Select
Application.CutCopyMode = False
Selection.Copy
Range("M3").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "CB"
Range("O4").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-7]>0,RC[-7]/100,"""")"
Range("O4").Select
Selection.Copy
Range("O5:O324").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("O3").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,RC:R[375]C)"
Range("O3").Select
Selection.ClearContents
ActiveCell.FormulaR1C1 = "=SUM(R[1]C:R[249]C)"
Range("AG1").Select
ActiveCell.FormulaR1C1 = "compte"
Range("AG3").Select
ActiveCell.FormulaR1C1 = "512206"
Range("AH1").Select
ActiveCell.FormulaR1C1 = "sens"
Range("AG4").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-25]>0,450101,"""")"
Range("AG4").Select
Selection.Copy
Range("AG5:AG184").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("AH3").Select
ActiveCell.FormulaR1C1 = "si("
Range("O3").Select
Range("AH3").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-19]>0,""C"",""D"")"
Range("AH3").Select
Selection.Copy
Range("AH4:AH218").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("AH3").Select
ActiveCell.FormulaR1C1 = "D"
Range("AH4").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-19]>0,""C"","""")"
Range("AH4").Select
Selection.Copy
Selection.End(xlDown).Select
Range("AH218:AH253").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH184").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH149").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH114").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH79").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH44").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH6").Select
ActiveWindow.LargeScroll Down:=-1
Range("AH5:AH254").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("AH4").Select
ActiveWindow.LargeScroll ToRight:=-1
Cells.Select
Range("L1").Activate
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("JT_SACD_PARIS_79182426_181113 (").Select
ActiveSheet.Range("$A$1:$AF$324").AutoFilter Field:=13, Criteria1:="SDD"
Application.CutCopyMode = False
ActiveWindow.SmallScroll ToRight:=20
Rows("8:8").Select
Range("U8").Activate
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveWindow.ScrollColumn = 20
ActiveWindow.ScrollColumn = 19
ActiveWindow.ScrollColumn = 18
ActiveWindow.ScrollColumn = 17
ActiveWindow.ScrollColumn = 16
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Range("J9").Select
Selection.Copy
Range("J8").Select
ActiveSheet.Paste
Range("AG8").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "512206"
Range("AG9").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-25]>0,""450101"","""")"
Range("AG9").Select
Selection.Copy
Range("AG35:AG390").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("AH8").Select
ActiveCell.FormulaR1C1 = "D"
Range("AH9").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-26]>0,""C"","""")"
Range("AH9").Select
Selection.Copy
Range("AH35:AH390").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.LargeScroll ToRight:=-1
Range("M9").Select
Selection.Copy
Range("M8").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll ToRight:=-8
Range("O9").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-7]>0,RC[-7]/100,"""")"
Range("O9").Select
Selection.Copy
Range("O35:O390").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("O8").Select
Selection.FormulaR1C1 = "="
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[1]C:R[374]C)"
Range("O8").Select
ActiveWindow.SmallScroll Down:=-18
Rows("8:330").Select
Range("H8").Activate
Selection.Copy
Sheets("Feuil1").Select
ActiveWindow.SmallScroll Down:=24
Rows("39:39").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 728
15 nov. 2018 à 15:49
Tu nous remets 2 fois ton code indigeste alors que l'on a répondu à ta question:

Sheets("JT_SACD_PARIS_79182426_181113 (").Select 


Sheets(1).Select 
0
queffelec125
22 nov. 2018 à 21:32
merci à tous pour vos réponses.

Je n'ai pas pu les mettre en application car vos réponses s'adressent à un spécialiste que je ne suis pas. Toutefois, en effectuant de nouvelles recherches sur internet j'ai trouvé une autre solution avec la fonction excel "filtre textuel" ou "filtre numérique".

Encore merci
0
Patrice33740 Messages postés 8556 Date d'inscription dimanche 13 juin 2010 Statut Membre Dernière intervention 2 mars 2023 1 775
22 nov. 2018 à 22:42
« vos réponses s'adressent à un spécialiste » ?????
Je vois pas en quoi il faut être spécialiste pour remplacer dans ta macro la ligne :
Sheets("JT_SACD_PARIS_79182426_181113 (").Select
par celle-ci :
Sheets(1).Select
0