A voir également:
- Exécuter une macro sur différents onglets
- Ce fichier contient l'historique des livres empruntés à la bibliothèque. combien de titres différents contient-il ? ✓ - Forum Excel
- Ce programme est écrit en python. il construit un mot secret dans une variable mais il ne l'affiche pas. modifiez-le pour qu'il affiche le mot secret. exécutez-le. quel est ce mot secret ? ✓ - Forum Python
- Macro logiciel - Télécharger - Organisation
- Macro recorder - Télécharger - Confidentialité
- Macro Recorder - Télécharger - Divers Utilitaires
6 réponses
Patrice33740
Messages postés
8556
Date d'inscription
dimanche 13 juin 2010
Statut
Membre
Dernière intervention
2 mars 2023
1 762
29 déc. 2010 à 23:21
29 déc. 2010 à 23:21
Essaies ce code :
Option Explicit
Sub Supprimer_Espaces()
Dim wsh As Worksheet
Dim cel As Range
For Each wsh In ActiveWorkbook.Worksheets
Set cel = Cells.Find(What:="Cout global", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Cout global"
Set cel = Cells.Find(What:="Heures travaillées", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Heures Travaillées"
Next wsh
End Sub
Merci pour votre réactivité et votre rapide réponse.
Malheureusement, cela fonctionne que sur l'onglet actif.
La macro ne s'exécute pas sur les autres onglets.
à l'aide de vos éléments, voilà ma nouvelle macro :
Sub Supprimer_Espaces()
Dim wsh As Worksheet
Dim cel As Range
For Each wsh In ActiveWorkbook.Worksheets
Set cel = Cells.Find(What:="Cout global", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Cout global"
Set cel = Cells.Find(What:="Heures travaillées", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Heures Travaillées"
Next wsh
End Sub
Avez-vous une autre idée ?
merci
Malheureusement, cela fonctionne que sur l'onglet actif.
La macro ne s'exécute pas sur les autres onglets.
à l'aide de vos éléments, voilà ma nouvelle macro :
Sub Supprimer_Espaces()
Dim wsh As Worksheet
Dim cel As Range
For Each wsh In ActiveWorkbook.Worksheets
Set cel = Cells.Find(What:="Cout global", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Cout global"
Set cel = Cells.Find(What:="Heures travaillées", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Heures Travaillées"
Next wsh
End Sub
Avez-vous une autre idée ?
merci
Patrice33740
Messages postés
8556
Date d'inscription
dimanche 13 juin 2010
Statut
Membre
Dernière intervention
2 mars 2023
1 762
29 déc. 2010 à 23:45
29 déc. 2010 à 23:45
Re,
Excuse-moi, j'ai été un peu trop rapide, voici le code :
Excuse-moi, j'ai été un peu trop rapide, voici le code :
Option Explicit
Sub Supprimer_Espaces()
Dim wsh As Worksheet
Dim cel As Range
For Each wsh In ActiveWorkbook.Worksheets
Set cel = wsh.Cells.Find(What:="Cout global", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Cout global"
Set cel = wsh.Cells.Find(What:="Heures travaillées", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Heures Travaillées"
Next wsh
End Sub
Parfait ! Merci pour votre aide.
c'est marche parfaitement.
je dormirai moins bête ce soir grâce à vous.
Je peux vous soumettre une autre hypothèse ?
Dans le cas où, j'aurai plusieurs onglets avant et après et que ces dernières ne doivent pas être affectées par la macro.
Puis-je spécifier les onglets sur lesquels la macro doit être exécuter ?
exple :
- les onglets compris entre la feuille AAAA et la feuille ZZZZ doivent être concernés par la macro.
ou
- les onglets n°1 ; 7 ; 23 ; ... ; 99 sont concernés par la macro
Merci d'avance.
c'est marche parfaitement.
je dormirai moins bête ce soir grâce à vous.
Je peux vous soumettre une autre hypothèse ?
Dans le cas où, j'aurai plusieurs onglets avant et après et que ces dernières ne doivent pas être affectées par la macro.
Puis-je spécifier les onglets sur lesquels la macro doit être exécuter ?
exple :
- les onglets compris entre la feuille AAAA et la feuille ZZZZ doivent être concernés par la macro.
ou
- les onglets n°1 ; 7 ; 23 ; ... ; 99 sont concernés par la macro
Merci d'avance.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Patrice33740
Messages postés
8556
Date d'inscription
dimanche 13 juin 2010
Statut
Membre
Dernière intervention
2 mars 2023
1 762
Modifié par Patrice33740 le 30/12/2010 à 00:08
Modifié par Patrice33740 le 30/12/2010 à 00:08
Re
1er cas :
2ème cas
Code à adapter en fonction du nom ou du numéro de feuille
Cordialement
Patrice
1er cas :
Sub Supprimer_Espaces()
Dim wsh As Worksheet
Dim cel As Range
For Each wsh In ActiveWorkbook.Worksheets
Select Case wsh.Name
Case "AAAA", "ZZZZ"
Set cel = wsh.Cells.Find(What:="Cout global", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Cout global"
Set cel = wsh.Cells.Find(What:="Heures travaillées", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Heures Travaillées"
End Select
Next wsh
End Sub
2ème cas
Sub Supprimer_Espaces()
Dim wsh As Worksheet
Dim cel As Range
For Each wsh In ActiveWorkbook.Worksheets
Select Case wsh.Index
Case 1, 7, 23 To 99
Set cel = wsh.Cells.Find(What:="Cout global", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Cout global"
Set cel = wsh.Cells.Find(What:="Heures travaillées", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not cel Is Nothing Then cel.Formula = "Heures Travaillées"
End Select
Next wsh
End Sub
Code à adapter en fonction du nom ou du numéro de feuille
Cordialement
Patrice
Un Grand MERCI à vous Patrice d'avoir pris le temps pour résoudre ma problématique.
Ce n'est pas tout à fait ce que je demandais, mais je m'en contente pleinement pour le moment où je n'ai pas beaucoup d'onglets.
Donc, j'ai nommé dans ma macro les onglets concernés.
Vous êtes vraiment doué. Passez une bonne soirée.
Encore merci
Cdt,
Ce n'est pas tout à fait ce que je demandais, mais je m'en contente pleinement pour le moment où je n'ai pas beaucoup d'onglets.
Donc, j'ai nommé dans ma macro les onglets concernés.
Vous êtes vraiment doué. Passez une bonne soirée.
Encore merci
Cdt,