IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

erreur méthode select de la classe range


Sujet :

Macros et VBA Excel

  1. #1
    Membre à l'essai
    Inscrit en
    Mars 2009
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 42
    Points : 24
    Points
    24
    Par défaut erreur méthode select de la classe range
    Bonjour,

    Je souhaite automatiser la mise en forme quotidienne d'un fichier Excel.
    J'ai enregistrer un macro en mode manuelle ce qui me donne le code ci-dessou. Seulement dès les premières lignes j'ai une erreur pour '
    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
    Rows("1:1").Select!
     
    Private Sub CommandButton2_Click()
        Sheets("tblTemp").Select
        Sheets("tblTemp").Name = "CS1"
     
    Sheets("CS1").Select
     
    Rows("1:1").Select     
        With Selection.Interior
            .ColorIndex = 6
            .Pattern = xlSolid
        End With
        Selection.Font.ColorIndex = 3
        Selection.Font.Bold = True
        Columns("A:E").Select
        Selection.EntireColumn.Hidden = True
        Columns("G:G").Select
        Selection.EntireColumn.Hidden = True
        Range("N1").Select
        ActiveCell.FormulaR1C1 = "Commentaires"
        Range("O1").Select
        ActiveCell.FormulaR1C1 = "Annexes"
        Rows("2:2").Select
        Range("F2").Activate
        ActiveWindow.FreezePanes = True
        Range("F1:O170").Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Rows("1:1").Select
        Range("F1").Activate
        Selection.AutoFilter
     
        Sheets("Accueil").Select
    End Sub
    Merci pour vos remarques!

  2. #2
    Expert éminent sénior Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Points : 31 877
    Points
    31 877
    Par défaut
    que fais cette ligne ici?
    En plus, Au lieu des select inutiles, pense comme ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
        Sheets("tblTemp").Name = "CS1"  'Attention ici, si tu renomme ta feuille, un 2ème lancement de ta procédure ne trouvera pas tblTemp
     
    With Sheets("CS1")
     
        With .Rows("1:1")
            .Interior.ColorIndex = 6
            .Interior.Pattern = xlSolid
            .Font.ColorIndex = 3
            .Font.Bold = True
        End With
        .Columns("A:E,G:G").Hidden = True
        .Range("N1").Value = "Commentaires"
    ...etc
    End With
    Attention quand même à ta première ligne, lisez le commentaire!

  3. #3
    Membre à l'essai
    Inscrit en
    Mars 2009
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 42
    Points : 24
    Points
    24
    Par défaut
    Merci mercatog,

    effectivement pour le début ca fonctionne ensuite ca semble pas être toujours aussi simple pr les autres fonctions mais la piste devrait me suffir à résoudre mon problème
    A bientot

  4. #4
    Membre à l'essai
    Inscrit en
    Mars 2009
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 42
    Points : 24
    Points
    24
    Par défaut
    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
     Private Sub CommandButton2_Click()
     
    worksheets("CS1").Activate
     
    With Sheets("feuil1")
     
        worksheets("feuil1").Cells.Select
     
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Cells.EntireRow.AutoFit
     
        With .Rows("1:1")
        .Interior.ColorIndex = 8
        .Interior.Pattern = xlSolid
        .Font.ColorIndex = 1
        .Font.Bold = True
        End With
     
        .Columns("H:H").ColumnWidth = 15
        .Columns("K:K").ColumnWidth = 50
        .Columns("J:J").ColumnWidth = 22.43
        .Columns("A:E").Hidden = True
        .Columns("G:G").Hidden = True
        .Range("M1").Value = "Commentaires"
        .Range("N1").Value = "N°"
     
    End With
     
    End Sub

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 11
    Dernier message: 09/07/2014, 16h40
  2. [XL-2010] Méthode Select de la classe Range échoué
    Par Identifiant_Anonyme dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 29/05/2014, 10h06
  3. Méthode select de la classe range a échoué
    Par BERRACHED SAID dans le forum Macros et VBA Excel
    Réponses: 23
    Dernier message: 06/06/2013, 13h11
  4. Réponses: 4
    Dernier message: 26/08/2010, 13h40
  5. Réponses: 13
    Dernier message: 29/06/2007, 18h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo