XL 2013 Executer une macro sur une feuille en la quittant

dna

XLDnaute Nouveau
Bonjour,

Je n'arrive pas à exécuter cette macro :

Private Sub Worksheet_Deactivate()
Rows("1:1").Select
Selection.AutoFilter
Selection.AutoFilter

ActiveWorkbook.Worksheets("FICHE").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("FICHE").AutoFilter.Sort.SortFields.Add Key:=Range( _
"E1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("FICHE").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub


J'ai cette erreur :

'1004' Err definie par l'application ou par l'objet = le debug s'arrête sur la 1er ligne...

Pouvez-vous m'aider ?
 

dna

XLDnaute Nouveau
Re : Executer une macro sur une feuille en la quittant

Si je peux abuser encore...

Cette fois-ci, toujours en quittant l'onglet, j'ai mis cette macro mais je ne peux plus sortir de l'onglet.. aïe

Sheets("Emploi").Select
Cells.Select
Selection.NumberFormat = "@"
Columns("E:G").Select
Selection.NumberFormat = "m/d/yyyy"
Columns("G:G").Select
Selection.Replace What:="", Replacement:=402498, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

ActiveWorkbook.Worksheets("Emploi").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Emploi").AutoFilter.Sort.SortFields.Add Key:=Range _
("G1:G855"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Emploi").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With


Je ne vois pas comment faire sans faire de select.
 

Pierrot93

XLDnaute Barbatruc
Re : Executer une macro sur une feuille en la quittant

Re,

essaye ceci, non testé...
Code:
With Sheets("Emploi")
    .Cells.NumberFormat = "@"
    .Columns("E:G").NumberFormat = "m/d/yyyy"
    .Columns("G:G").Replace What:="", Replacement:=402498, LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
End With
With ActiveWorkbook.Worksheets("Emploi").AutoFilter.Sort
    .SortFields.Clear
    .SortFields.Add Key:=.Range _
    ("G1:G855"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortNormal
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
 

Statistiques des forums

Discussions
312 789
Messages
2 092 120
Membres
105 220
dernier inscrit
lmerm