[vba]action après selection danss liste déroulante

Yannanou

XLDnaute Nouveau
Bonjour,

Je fait créé une fenetre avec liste déroulante, mais après avoir fait le choix dans cette liste (deux dates) j'aimerai copier toutes les lignes qui sont comprises entre ces deux dates.
Je pense que ma définition de variable est mauvaise.

J'ai mis un petit mot à coté de l'endroit ou il affiche l'erreur.
Merci de votre interet.
Bonne soirée.

Yann



Une partie de la macro :

'*******************************************************************************************/
' /
'Nom: ListeDeroulanteModifiable /
'Auteur: Yann /
'Date: 13/7/2007 /
' /
'Déscription: Pour afficher la fenetre "choix date" et lancer la macro qui lui /
' incombe. Celle-ci conciste à récuperer les information des incidents /
' entre deux dates, de les copiers dans la feulle "tri daté", et de les /
' mettre en forme. /
' /
'*******************************************************************************************/

Private Sub UserForm_Activate()

'********************************************************************************************/
' Renvoit à la mise en forme de la fenetre "ListeDeroulanteModifiable"***********************/
'********************************************************************************************/

Sheets("Données").Select
Dim I As Integer
Dim nbligne As Long
nbligne = Application.WorksheetFunction.CountA(Range("B:B"))
ListeDeroulanteModifiable.Listedate.Clear
For I = 1 To nbligne
ListeDeroulanteModifiable.Listedate.AddItem Cells(I, 2).Value
ListeDeroulanteModifiable.Listedate2.AddItem Cells(I, 2).Value
Next
Listedate.ListIndex = 0

End Sub

Private Sub Valider_Click()

'********************************************************************************************/
' Définition des variables*******************************************************************/
'********************************************************************************************/

ListeDeroulanteModifiable.Hide
Application.ScreenUpdating = False
Marque = Listedate.Value
Marque2 = Listedate2.Value

'********************************************************************************************/
' Renvoit à la gestion d'erreur en bas de page***********************************************/
'********************************************************************************************/

On Error GoTo GestionErreur

'********************************************************************************************/
' Remise à zero de la feuille "compte rendu daté"********************************************/
'********************************************************************************************/

Sheets("Compte rendu daté").Select
Cells.Select
Selection.Delete Shift:=xlUp
Sheets("Données").Select
ActiveSheet.ShowAllData
Application.Dialogs(xlDialogFilter).Show 2

'********************************************************************************************/
' Selection et activation de l'affichage total de la feuille "Données"***********************/
'********************************************************************************************/

rangecopy = Marque: Marque 2 ==========> c'est ici qu'il m'affiche une erreur de compilation
Rows(rangecopy).Select
Range(Marque, Marque2).Copy

Selection.Copy
Sheets("Compte rendu daté").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True

'*********************************************************************************************/
' Mise en forme de la feuille "Compte rendu daté"*********************************************/
'*********************************************************************************************/

Selection.Interior.ColorIndex = xlNone
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Range("1:1,9:9,15:15,16:16,18:18").Select
Range("A18").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Range("A1").Select
ActiveCell.FormulaR1C1 = "D.Début"
With ActiveCell.Characters(Start:=1, Length:=17).Font
.Name = "Arial"
.FontStyle = "Gras"
.Size = 10
.Strikethrough = False...........
 

porcinet82

XLDnaute Barbatruc
Re : [vba]action après selection danss liste déroulante

re,

J'aurai du testé mon code au lieu de mettre des conneries...
Cette fois ca roule :
Code:
With Sheets("Compte rendu daté")
    Rows(1).Copy
    .Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
    Rows(adress_marque & ":" & adress_marque2).Copy
   .Range("B1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End With

Petit précision juste au cas ou, le code ci-dessus est a mettre a la place de celui-ci :
Code:
Rows(adress_marque & ":" & adress_marque2).Copy
With Sheets("Compte rendu daté").Range("A1")
    .PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End With

@+
 

Yannanou

XLDnaute Nouveau
Re : [vba]action après selection danss liste déroulante

ça marche parfaitement, puis-je ajouter mes modifications comme pour la page "Compte rendu quotidien", c'est a dire:

Code:
'********************************************************************************************/
' Mise en forme de la feuille "Compte rendu quotidien"***************************************/
'********************************************************************************************/
    
        Selection.Interior.ColorIndex = xlNone
        Columns("A:A").EntireColumn.AutoFit
        Columns("B:B").EntireColumn.AutoFit
        Columns("C:C").EntireColumn.AutoFit
        Range("1:1,9:9,15:15,16:16,18:18").Select
        Range("A18").Activate
        Application.CutCopyMode = False
        Selection.Delete Shift:=xlUp
        Range("A1").Select
        ActiveCell.FormulaR1C1 = "D.Début"
    With ActiveCell.Characters(Start:=1, Length:=17).Font
        .Name = "Arial"
        .FontStyle = "Gras"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
        Rows("7:9").Select
        Application.CutCopyMode = False
        Selection.Cut
        Rows("1:1").Select
        Selection.Insert Shift:=xlDown
        Rows("1:1").Select
        Selection.Cut
        Rows("4:4").Select
        Selection.Insert Shift:=xlDown
        Rows("13:13").Select
        Selection.Cut
        Rows("3:3").Select
        Selection.Insert Shift:=xlDown
        Rows("11:13").Select
        Selection.Cut
        Rows("8:8").Select
        Selection.Insert Shift:=xlDown
        Range("A10").Select
        ActiveCell.FormulaR1C1 = "Action"
        Range("A11").Select
        Sheets("Compte rendu quotidien").Select
        Rows("13:13").Select
        Selection.Cut
        Rows("15:15").Select
        Selection.Insert Shift:=xlDown
        Range("A1").Select
        ActiveCell.FormulaR1C1 = "Caisse régionale"
        Range("A2").Select
        ActiveCell.FormulaR1C1 = "Intitulé de l'incident:"
        Range("A3").Select
        ActiveCell.FormulaR1C1 = "N°Interv:"
    With ActiveCell.Characters(Start:=1, Length:=9).Font
            .Name = "Arial"
            .FontStyle = "Gras"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
    End With
        Range("A4").Select
        ActiveCell.FormulaR1C1 = "Serveur:"
        Range("A5").Select
        ActiveCell.FormulaR1C1 = "D.Début:"
        Range("A6").Select
        ActiveCell.FormulaR1C1 = "H.Début Incidents:"
    With ActiveCell.Characters(Start:=1, Length:=18).Font
        .Name = "Arial"
        .FontStyle = "Gras"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
        Range("A7").Select
        ActiveCell.FormulaR1C1 = "H.Début ASFS:"
    With ActiveCell.Characters(Start:=1, Length:=13).Font
        .Name = "Arial"
        .FontStyle = "Gras"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
        Range("A8").Select
        ActiveCell.FormulaR1C1 = "Cause:"
        Range("A9").Select
        ActiveCell.FormulaR1C1 = "Impact:"
        Range("A10").Select
        ActiveCell.FormulaR1C1 = "Action:"
        Range("A11").Select
        ActiveCell.FormulaR1C1 = "D.Fin:"
        Range("A12").Select
        ActiveCell.FormulaR1C1 = "H.Fin ASFS:"
    With ActiveCell.Characters(Start:=1, Length:=11).Font
        .Name = "Arial"
        .FontStyle = "Gras"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
        Range("A13:A14").Select
        ActiveCell.FormulaR1C1 = "Destinataire:"
        Range("A14").Select
        ActiveCell.FormulaR1C1 = "H.Fin Incidents:"
    With ActiveCell.Characters(Start:=1, Length:=16).Font
        .Name = "Arial"
        .FontStyle = "Gras"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
        Range("A15").Select
        ActiveCell.FormulaR1C1 = "Statut:"
        Range("A16").Select
        ActiveCell.FormulaR1C1 = "Intervenant:"
        Rows("15:15").Select
        Selection.Cut
        Rows("13:13").Select
        Selection.Insert Shift:=xlDown
        Range("A1:A16").Select
        Range("A16").Activate
    With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlBottom
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
        Range("A1").Select
        Selection.Font.ColorIndex = 3
        Selection.Font.Italic = True
        Range("A3").Select
        ActiveCell.FormulaR1C1 = "N°Intervention:"
    With ActiveCell.Characters(Start:=1, Length:=15).Font
        .Name = "Arial"
        .FontStyle = "Gras"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
        Rows("1:1").Select
        Selection.Font.ColorIndex = 3
        Selection.Font.Bold = False
        Selection.Font.Bold = True

Merci d'avance et encor merci pour tout!

Yann
 

porcinet82

XLDnaute Barbatruc
Re : [vba]action après selection danss liste déroulante

re,

Y'a pas de problème, tu peux ajouter du code de mise en page. Un petit conseil que je t'ai deja donné, c'est de viré tout tes Select ou Activate
Par exemple, tu peux remplacer
Code:
Rows("7:9").Select
Selection.Cut
[COLOR=seagreen][B]'par[/B][/COLOR]
Rows("7:9").Cut
 
[B][COLOR=seagreen]'ou encore[/COLOR][/B] 
Range("A15").Select
ActiveCell.FormulaR1C1 = "Statut:"
[COLOR=seagreen][B]'par[/B][/COLOR]
Range("A15").FormulaR1C1 = "Statut:"

@+
 

porcinet82

XLDnaute Barbatruc
Re : [vba]action après selection danss liste déroulante

re,

Et bien si tu l'as copié tel quel, c'est normal que ca ne fonctionne pas. Tu es sur la feuille Données et tu veux mettre en page la feuille Compte rendu daté. Donc soit tu utilises un With Sheets("Compte rendu daté") sachant que comme apres tu as d'autres With, tu vas t'amuser a tout remettre, soit tu fais un Sheets("Compte rendu daté").Select

@+
 

Yannanou

XLDnaute Nouveau
Re : [vba]action après selection danss liste déroulante

Le "Sheets("Compte rendu daté").Select" il suffit de le mettre un fois au début, si c'est ça, ça ne marche toujours pas, pourtant je n'ai pas l'impression qu'il y ai la sellection d'une autre feuille!

Yann
 

porcinet82

XLDnaute Barbatruc
Re : [vba]action après selection danss liste déroulante

re,

Bon, il te suffit de mettre le code de la manière suivante :
Code:
[COLOR=seagreen]'*********************************************************************************************/
' Mise en forme de la feuille "Compte rendu daté" ********************************************/
'*********************************************************************************************/[/COLOR]
Sheets("Compte rendu daté").Select
[COLOR=seagreen]'le reste de ton code ici[/COLOR]

Par contre, je ne sais pas si le code que tu avais fait va faire ce que tu souhaites etant donné que tu avais du le faire avant via l'enregistreur de macro... A mon avis, tu devrais le refaire ou l'adapter !!!

@+
 

Yannanou

XLDnaute Nouveau
Re : [vba]action après selection danss liste déroulante

Dac merci bien je vois ça et je te tiens au courant.
Car là j'ai essaie comme tu me l'a mis, c'est ce que j'avait fait et ça marche pas.
Merci

Yann
 
Dernière édition:

Discussions similaires

Réponses
3
Affichages
569

Membres actuellement en ligne

Statistiques des forums

Discussions
312 104
Messages
2 085 349
Membres
102 870
dernier inscrit
Armisa