Lancer une macro lors de la saisie d'une cellule

Bonjour,

j'ai une macro qui genere une feuille excelle avec un entete de tabeau, ce que je veux faire c'est lorsque je saisi dans une cellule de la premiere ligne vide apres l'entete du tableau, une macro se lance automatiquement pour ajouter les bordure et colore le fond de la plage de cette ligne.

SVP comment je peux faire cela? et c'est quoi l'evenement qui lancera cette macro?

Merci beaucoup

Bonsoir

De cette façon, peut être:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column > 1 Then Exit Sub

If Target.Address >= "$A$2" Or Target.Address <= "$A$3000" Then
    With Target.Borders()
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With

End If

End Sub

j'ai essayé mais ça donne rien

re

Cela ne donne rien avec les éléments que nous avons,

L'exemple que je t'ai donné permet d'encadrer la cellule ou l'on a inscrit quelque chose ( et cela dans la colonne A, il faut la modifier si le critere n'est pas cette colonne

CB60 a écrit :

re

Cela ne donne rien avec les éléments que nous avons,

L'exemple que je t'ai donné permet d'encadrer la cellule ou l'on a inscrit quelque chose ( et cela dans la colonne A, il faut la modifier si le critere n'est pas cette colonne

je sais mais ça ne marche pas.

Bonsoir,

le plus intéressant serait peut-être de voir ta macro d'importation, et ainsi pouvoir répondre au mieux...

Mais il me semble qu'une simple mise en forme conditionnelle pourrait suffire....

A voir....

felix a écrit :

Bonsoir,

le plus intéressant serait peut-être de voir ta macro d'importation, et ainsi pouvoir répondre au mieux...

Mais il me semble qu'une simple mise en forme conditionnelle pourrait suffire....

A voir....

bon voila ma macro qui genere la feuille:

Sub genererEA()
'**********************************************************************************************************************************
'                                                   Déclarations
'**********************************************************************************************************************************
Dim NomFeuille As String

Dim i As Integer

Dim b_existe As Boolean
'**********************************************************************************************************************************
'                                                   Traitements
'**********************************************************************************************************************************
'Donner la main à l'utilisateur pour donner le nom de la feuille
NomFeuille = InputBox("Donner le nom de la feuille à créer", "Nom de la feuille")

For i = 1 To Sheets.Count
    If Sheets(i).Name = NomFeuille Then
       b_existe = True
    End If
Next

If b_existe Then
    MsgBox ("Ce Nom de feuille existe déja")
    Exit Sub
End If

'renomer la feuille
If NomFeuille = "" Then
    Exit Sub
    Else
        ActiveWorkbook.Sheets.Add after:=Worksheets(Worksheets.Count)
        ActiveSheet.Name = NomFeuille
        ActiveWindow.DisplayGridlines = False
End If

With Sheets(NomFeuille)

    'creer l'entete de la feuille:
    'fusionner les cellules de l'entete
    .Range(Cells(2, 2), Cells(2, 12)).MergeCells = True
    'ecrire l'entete
    .Range(Cells(2, 2), Cells(2, 12)).Value = "Etat d'avancement des demandes en cours"
    'mettre l'entete en gras
    .Range(Cells(2, 2), Cells(2, 12)).Font.Bold = True
    'colorer le font des cellules fusionnées en jaune
    .Range(Cells(2, 2), Cells(2, 12)).Interior.ColorIndex = 36
    'definir la hauteur des cellules
    .Range(Cells(2, 2), Cells(2, 12)).RowHeight = 25
    'centrer l'entete
    .Range(Cells(2, 2), Cells(2, 12)).HorizontalAlignment = xlCenter
    .Range(Cells(2, 2), Cells(2, 12)).VerticalAlignment = xlCenter
    'mettre la police de l'entete en Baskerville Old Face
    .Range(Cells(2, 2), Cells(2, 12)).Font.Name = "Baskerville Old Face"
    'definir la taille de la police
    .Range(Cells(2, 2), Cells(2, 12)).Font.Size = 12

    'mettre la bordure
    .Range(Cells(2, 2), Cells(2, 12)).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range(Cells(2, 2), Cells(2, 12)).Borders(xlEdgeLeft).Weight = xlThick

    .Range(Cells(2, 2), Cells(2, 12)).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range(Cells(2, 2), Cells(2, 12)).Borders(xlEdgeTop).Weight = xlThick

    .Range(Cells(2, 2), Cells(2, 12)).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range(Cells(2, 2), Cells(2, 12)).Borders(xlEdgeBottom).Weight = xlThick

    .Range(Cells(2, 2), Cells(2, 12)).Borders(xlEdgeRight).LineStyle = xlContinuous
    .Range(Cells(2, 2), Cells(2, 12)).Borders(xlEdgeRight).Weight = xlThick

    'Zone de texte
    .Shapes.AddTextbox(msoTextOrientationHorizontal, 300#, 50, 300, 90#).Select
    Selection.Characters.Text = ""
    With Selection.Font
        .Name = "Arial"
        .FontStyle = "Normal"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
    Selection.Characters.Text = "Date Cible:" & Chr(10) & "" & Chr(10) & ""
    With Selection.Characters(Start:=1, Length:=13).Font
        .Name = "Arial"
        .FontStyle = "Gras"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleSingle
        .ColorIndex = xlAutomatic
    End With
    Selection.Characters.Text = "Date Cible:" & Chr(10) & "" & Chr(10) & ""
    With Selection.Characters(Start:=1, Length:=13).Font
        .Name = "Arial"
        .FontStyle = "Gras"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleSingle
        .ColorIndex = xlAutomatic
    End With
    Selection.Characters.Text = _
        "Date Cible:" & Chr(10) & "" & Chr(10) & "Date de Livraison FDM            :" & Chr(10) & "" & Chr(10) & "Priorité                                   :" & Chr(10) & "Date de Livraison en Re7         :"
    With Selection.Characters(Start:=1, Length:=13).Font
        .Name = "Arial"
        .FontStyle = "Gras"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleSingle
        .ColorIndex = xlAutomatic
    End With
    With Selection.Characters(Start:=14, Length:=116).Font
        .Name = "Arial"
        .FontStyle = "Normal"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With

    'creation du tableau d'etat d'avancement:
    'creation des entetes du tableau
    .Range("B" & 12).Interior.ColorIndex = 15
    .Range("B" & 12).RowHeight = 40
    .Range("B" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("B" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("B" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("B" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("B" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("B" & 12).Borders(xlEdgeBottom).Weight = xlMedium
    .Range("B" & 12).Borders(xlEdgeRight).LineStyle = xlContinuous
    .Range("B" & 12).Borders(xlEdgeRight).Weight = xlMedium

    .Range("C" & 12).Interior.ColorIndex = 15
    .Range("C" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("C" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("C" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("C" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("C" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("C" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("D" & 12).Interior.ColorIndex = 15
    .Range("D" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("D" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("D" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("D" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("D" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("D" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("E" & 12).Interior.ColorIndex = 15
    .Range("E" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("E" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("E" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("E" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("E" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("E" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("F" & 12).Interior.ColorIndex = 15
    .Range("F" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("F" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("F" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("F" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("F" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("F" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("G" & 12).Interior.ColorIndex = 15
    .Range("G" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("G" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("G" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("G" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("G" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("G" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("H" & 12).Interior.ColorIndex = 15
    .Range("H" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("H" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("H" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("H" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("H" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("H" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("I" & 12).Interior.ColorIndex = 15
    .Range("I" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("I" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("I" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("I" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("I" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("I" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("J" & 12).Interior.ColorIndex = 15
    .Range("J" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("J" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("J" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("J" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("J" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("J" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("K" & 12).Interior.ColorIndex = 15
    .Range("K" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("K" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("K" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("K" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("K" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("K" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("L" & 12).Interior.ColorIndex = 15
    .Range("L" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("L" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("L" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("L" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("L" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("L" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("M" & 12).Interior.ColorIndex = 15
    .Range("M" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("M" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("M" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("M" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("M" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("M" & 12).Borders(xlEdgeBottom).Weight = xlMedium

    .Range("N" & 12).Interior.ColorIndex = 15
    .Range("N" & 12).Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Range("N" & 12).Borders(xlEdgeLeft).Weight = xlMedium
    .Range("N" & 12).Borders(xlEdgeTop).LineStyle = xlContinuous
    .Range("N" & 12).Borders(xlEdgeTop).Weight = xlMedium
    .Range("N" & 12).Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Range("N" & 12).Borders(xlEdgeBottom).Weight = xlMedium
    .Range("N" & 12).Borders(xlEdgeRight).LineStyle = xlContinuous
    .Range("N" & 12).Borders(xlEdgeRight).Weight = xlMedium

    .Columns("A:A").ColumnWidth = 2.5
    .Columns("B:B").ColumnWidth = 2.5

    .Range("C" & 12).Value = "N° Fiche"
    .Columns("C:C").ColumnWidth = 10
    .Range("C" & 12).WrapText = True
    .Range("C" & 12).Font.Bold = True
    .Range("C" & 12).HorizontalAlignment = xlCenter
    .Range("C" & 12).VerticalAlignment = xlCenter

    .Range("D" & 12).Value = "Version précédente (avec historique)"
    .Columns("D:D").ColumnWidth = 10
    .Range("D" & 12).WrapText = True
    .Range("D" & 12).Font.Bold = True
    .Range("D" & 12).HorizontalAlignment = xlCenter
    .Range("D" & 12).VerticalAlignment = xlCenter

    .Range("E" & 12).Value = "Date estimée ou réellle de livraion de la FDM (avec historique)"
    .Columns("E:E").ColumnWidth = 15
    .Range("E" & 12).WrapText = True
    .Range("E" & 12).Font.Bold = True
    .Range("E" & 12).Font.Size = 8
    .Range("E" & 12).HorizontalAlignment = xlCenter
    .Range("E" & 12).VerticalAlignment = xlCenter

    .Range("F" & 12).Value = "Date validation FDM"
    .Columns("F:F").ColumnWidth = 15
    .Range("F" & 12).WrapText = True
    .Range("F" & 12).Font.Bold = True
    .Range("F" & 12).HorizontalAlignment = xlCenter
    .Range("F" & 12).VerticalAlignment = xlCenter

    .Range("G" & 12).Value = "Date de mise en recette estimée ou réelle (avec historique)"
    .Columns("G:G").ColumnWidth = 15
    .Range("G" & 12).WrapText = True
    .Range("G" & 12).Font.Bold = True
    .Range("G" & 12).HorizontalAlignment = xlCenter
    .Range("G" & 12).VerticalAlignment = xlCenter

    .Range("H" & 12).Value = "RAF ANA"
    .Columns("H:H").ColumnWidth = 10
    .Range("H" & 12).WrapText = True
    .Range("H" & 12).Font.Bold = True
    .Range("H" & 12).HorizontalAlignment = xlCenter
    .Range("H" & 12).VerticalAlignment = xlCenter

    .Range("I" & 12).Value = "RAF RTU"
    .Columns("I:I").ColumnWidth = 10
    .Range("I" & 12).WrapText = True
    .Range("I" & 12).Font.Bold = True
    .Range("I" & 12).HorizontalAlignment = xlCenter
    .Range("I" & 12).VerticalAlignment = xlCenter

    .Range("J" & 12).Value = "Date FV/FR recette"
    .Columns("J:J").ColumnWidth = 15
    .Range("J" & 12).WrapText = True
    .Range("J" & 12).Font.Bold = True
    .Range("J" & 12).HorizontalAlignment = xlCenter
    .Range("J" & 12).VerticalAlignment = xlCenter

    .Range("K" & 12).Value = "Objet"
    .Columns("K:K").ColumnWidth = 25
    .Range("K" & 12).WrapText = True
    .Range("K" & 12).Font.Bold = True
    .Range("K" & 12).HorizontalAlignment = xlCenter
    .Range("K" & 12).VerticalAlignment = xlCenter

    .Range("L" & 12).Value = "Avancement"
    .Columns("L:L").ColumnWidth = 25
    .Range("L" & 12).WrapText = True
    .Range("L" & 12).Font.Bold = True
    .Range("L" & 12).HorizontalAlignment = xlCenter
    .Range("L" & 12).VerticalAlignment = xlCenter

    .Range("M" & 12).Value = "Commentaires"
    .Columns("M:M").ColumnWidth = 60
    .Range("M" & 12).WrapText = True
    .Range("M" & 12).Font.Bold = True
    .Range("M" & 12).HorizontalAlignment = xlCenter
    .Range("M" & 12).VerticalAlignment = xlCenter

    .Range("N" & 12).Value = "Traitements et pré-requis"
    .Columns("N:N").ColumnWidth = 35
    .Range("N" & 12).WrapText = True
    .Range("N" & 12).Font.Bold = True
    .Range("N" & 12).HorizontalAlignment = xlCenter
    .Range("N" & 12).VerticalAlignment = xlCenter

End With

End Sub

ce que je veux c quand je saisi un N°fiche je veux que toute la ligne soit avec des bordure et un fonf vert pistache.

Re-,

regarde le fichier joint, j'ai un peu raccourci ton code.....

Et j'ai rajouté un code, qui rajoute un autre code dans l'évènement de la feuille que tu viens de créer....

En cliquant sur le rectangle, tu crées une nouvelle feuille

dans cette nouvelle feuille, tu as un évènement Worksheet_Change, si tu modifies une cellule de la colonne C, tu entoures les cellules, et tu les mets en vert

https://www.excel-pratique.com/~files/doc/nsqualli_v1.xls

Bonjour,

MERCI Beaucoup Felix, c'est exactement ce que je voulais.

il me reste juste de faire des ptites recifications pour optimiser le code.

Rechercher des sujets similaires à "lancer macro lors saisie"