aplliquer une macro à 20 feuilles

RoadRunner

XLDnaute Nouveau
Bonjour

J'ai presque réussi à faire ce que je voulai...
Mais, eh oui ! dans la macro suivante j'aimerai ajouter ce qu'il faut pour que lorsqu'elle s'exécute, elle applique ce qu'elle fait aux 20 feuilles du classeur, celles ci étant numérotées de 01 à 20

voila la macro :
----------------------------------------------------------------------------
Option Explicit

Sub Transformation_HHMMSS()
Dim Cell As Range
Dim TmpMM As String
Dim TmpSS As String
Dim Container As Variant

For Each Cell In Union(Range('B4:B99'), Range('C4:C99'))
If InStr(1, Cell, 'mn', 1) <> 0 Then
On Error Resume Next
Container = Split(Cell, 'mn')
TmpMM = Val(Container(0))
TmpSS = Val(Container(1))
Cell = '00:' & Format(TmpMM, '00') & ':' & Format(TmpSS, '00')
End If
Next

ActiveWindow.SmallScroll Down:=69
Range('B100').Select
ActiveCell.FormulaR1C1 = '=AVERAGE(R[-96]C:R[-1]C)'
Range('C100').Select
ActiveCell.FormulaR1C1 = '=AVERAGE(R[-96]C:R[-1]C)'

End Sub

----------------------------------------------------------------------------
(je pense qu'il faut rajouter un truc du genre 'for each feuil...' mais je ne connais pas vraiment)

en tout cas merci d'avance

petit bonjour à Thierry et Sylvie en passant
 

porcinet82

XLDnaute Barbatruc
salut,

une solution parmis d'autres, moi il m'arrive d'utiliser un simple for. ce qui donnerai dans ton cas:


Sub Transformation_HHMMSS()
...

for i=1 to 20
sheets(i).select

For Each Cell In Union(Range('B4:B99'), Range('C4:C99'))
...
ActiveCell.FormulaR1C1 = '=AVERAGE(R[-96]C:R[-1]C)'
next i

End Sub

bon courage pour la suite

@+
 

Shining Hawk

XLDnaute Junior
Salut RoadRunner,


t'as tout bon: il faut effectivement utiliser un truc du genre for each:

-soit tu mets

Option Explicit

Sub Transformation_HHMMSS()
Dim Cell As Range
Dim TmpMM As String
Dim TmpSS As String
Dim Container As Variant
Dim feuille As Worksheet

For each feuille In ThisWorkbook.Sheets
feuille.select

For Each Cell In Union(Range('B4:B99'), Range('C4:C99'))
If InStr(1, Cell, 'mn', 1) <> 0 Then
On Error Resume Next
Container = Split(Cell, 'mn')
TmpMM = Val(Container(0))
TmpSS = Val(Container(1))
Cell = '00:' & Format(TmpMM, '00') & ':' & Format(TmpSS, '00')
End If
Next

ActiveWindow.SmallScroll Down:=69
Range('B100').Select
ActiveCell.FormulaR1C1 = '=AVERAGE(R[-96]C:R[-1]C)'
Range('C100').Select
ActiveCell.FormulaR1C1 = '=AVERAGE(R[-96]C:R[-1]C)'

next feuille
End Sub

-soit tu appelles plusieurs fois la même macro:

sub lance_traitement()
Dim feuille As Worksheet
For Each feuille In ThisWorkbook.Sheets
feuille.select
call Transformation_HHMMSS
Next feuille
end sub

- ou alors ...
sub lance_traitement2()
Dim feuille As Worksheet
Dim i as Integer
For i = 1 To ThisWorkbook.Sheets.Count
Sheets(i).select
call Transformation_HHMMSS
Next
end sub


En espérant que cela te convienne,
Bonne prog.
 

RoadRunner

XLDnaute Nouveau
Je reviens car problème...

j'ai utilisé ça :

Sub Transformation_HHMMSS()
Dim Cell As Range
Dim TmpMM As String
Dim TmpSS As String
Dim Container As Variant
Dim feuille As Worksheet

For each feuille In ThisWorkbook.Sheets
feuille.select
For Each Cell In Union(Range('B4:B99'), Range('C4:C99'))
If InStr(1, Cell, 'mn', 1) <> 0 Then
On Error Resume Next
Container = Split(Cell, 'mn')
TmpMM = Val(Container(0))
TmpSS = Val(Container(1))
Cell = '00:' & Format(TmpMM, '00') & ':' & Format(TmpSS, '00')
End If
Next

ActiveWindow.SmallScroll Down:=69
Range('B100').Select
ActiveCell.FormulaR1C1 = '=AVERAGE(R[-96]C:R[-1]C)'
Range('C100').Select
ActiveCell.FormulaR1C1 = '=AVERAGE(R[-96]C:R[-1]C)'

next feuille
End Sub

mais erreur 1004
la methode 'Select' de l'objet '_Worksheet' a échoué

que fiare ?
 

_Thierry

XLDnaute Barbatruc
Repose en paix
Bonjour RoadieWoodPicker ;) le Fil, le Forum

Tiens il me dit quelque chose ce code... Merci de ton Petit Bonjour à Sylvie et moi-même

Essaie tout simplement sans Select...

Option Explicit

Sub Transformation_HHMMSS()
Dim Cell As Range
Dim TmpMM As String
Dim TmpSS As String
Dim Container As Variant
Dim WS As Worksheet

&nbsp; &nbsp;
For Each WS In ActiveWorkbook.Worksheets
&nbsp; &nbsp; &nbsp; &nbsp;
With WS
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
For Each Cell In Union(.Range('B4:B99'), .Range('C4:C99'))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
If InStr(1, Cell, 'mn', 1) <> 0 Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
On Error Resume Next
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Container = Split(Cell, 'mn')
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TmpMM = Val(Container(0))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TmpSS = Val(Container(1))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Cell = '00:' & Format(TmpMM, '00') & ':' & Format(TmpSS, '00')
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
End If
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
Next Cell
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
With .Range('B100')
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Formula = '=AVERAGE(B4:B88)'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .NumberFormat = 'hh:mm:ss'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
End With
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
With .Range('C100')
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Formula = '=AVERAGE(C4:C88)'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .NumberFormat = 'hh:mm:ss'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
End With
&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;
End With
&nbsp; &nbsp;
Next WS
End Sub

Mais fait bien attention au '.' devant les 'Range'...


Bonne Soirée
[ol]@+Thierry[/ol]
 

Discussions similaires

Réponses
7
Affichages
553

Statistiques des forums

Discussions
312 368
Messages
2 087 669
Membres
103 633
dernier inscrit
Surfer