Est il possible d'intégrer des si et des ou dans une macro
Bonjour à tous,
tout d'abord avant de vous poser ma question je tiens à vous dire que je suis complètement novice dans excel et de plus dans les macro.
Voici ma première question: est-il possible d'ajouter des si et des ou dans un macro ?
Pourquoi cette question, alors j'ai créé un fichier excel avec des macro qui me permet de ranger trier et près à imprimer une liste de stock en cliquant sur un bouton, à la fin de l'exécution de mon macro je me retrouve dans l'aperçue avant impression, jusque la tout va bien à partir de là je voudrais savoir s'il est possible que quand on clique sur imprimer ou sur fermer l'aperçu on revienne non pas sur la feuille qui allait être imprimé (feuille 2) mais sur la feuille ou il y a tous mes boutons (feuille 1) tout en sachant que si on clique sur imprimer cela imprime quand même.
Deuxième question : peut-on éviter la visualisation du défilement de la macro ?
Quand je clique sur un de mes boutons je voudrais arriver directement à mon aperçu avant impression sans voir le déroulement de toutes mes pages.
voici en exemple un de mes macro :
' Touche de raccourci du clavier: Ctrl+Maj+H
'
Sheets("Feuil3").Select
Range("A1:H2640").Select
Selection.Copy
Sheets("Feuil5").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Feuil2").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
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
Selection.ClearContents
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("A1").Select
Sheets("Feuil5").Select
Selection.ClearContents
Range("A1").Select
Sheets("Feuil3").Select
ActiveWindow.ScrollRow = 2599
ActiveWindow.ScrollRow = 2595
ActiveWindow.ScrollRow = 2592
ActiveWindow.ScrollRow = 2588
ActiveWindow.ScrollRow = 2582
ActiveWindow.ScrollRow = 2575
ActiveWindow.ScrollRow = 2565
ActiveWindow.ScrollRow = 2551
ActiveWindow.ScrollRow = 2531
ActiveWindow.ScrollRow = 2507
ActiveWindow.ScrollRow = 2483
ActiveWindow.ScrollRow = 2456
ActiveWindow.ScrollRow = 2426
ActiveWindow.ScrollRow = 2389
ActiveWindow.ScrollRow = 2351
ActiveWindow.ScrollRow = 2257
ActiveWindow.ScrollRow = 2158
ActiveWindow.ScrollRow = 2108
ActiveWindow.ScrollRow = 2019
ActiveWindow.ScrollRow = 1975
ActiveWindow.ScrollRow = 1881
ActiveWindow.ScrollRow = 1833
ActiveWindow.ScrollRow = 1718
ActiveWindow.ScrollRow = 1660
ActiveWindow.ScrollRow = 1545
ActiveWindow.ScrollRow = 1495
ActiveWindow.ScrollRow = 1406
ActiveWindow.ScrollRow = 1362
ActiveWindow.ScrollRow = 1271
ActiveWindow.ScrollRow = 1227
ActiveWindow.ScrollRow = 1136
ActiveWindow.ScrollRow = 1092
ActiveWindow.ScrollRow = 1003
ActiveWindow.ScrollRow = 963
ActiveWindow.ScrollRow = 885
ActiveWindow.ScrollRow = 858
ActiveWindow.ScrollRow = 783
ActiveWindow.ScrollRow = 746
ActiveWindow.ScrollRow = 682
ActiveWindow.ScrollRow = 655
ActiveWindow.ScrollRow = 628
ActiveWindow.ScrollRow = 604
ActiveWindow.ScrollRow = 577
ActiveWindow.ScrollRow = 533
ActiveWindow.ScrollRow = 519
ActiveWindow.ScrollRow = 499
ActiveWindow.ScrollRow = 485
ActiveWindow.ScrollRow = 468
ActiveWindow.ScrollRow = 455
ActiveWindow.ScrollRow = 438
ActiveWindow.ScrollRow = 428
ActiveWindow.ScrollRow = 418
ActiveWindow.ScrollRow = 414
ActiveWindow.ScrollRow = 407
ActiveWindow.ScrollRow = 404
ActiveWindow.ScrollRow = 401
ActiveWindow.ScrollRow = 390
ActiveWindow.ScrollRow = 387
ActiveWindow.ScrollRow = 377
ActiveWindow.ScrollRow = 374
ActiveWindow.ScrollRow = 367
ActiveWindow.ScrollRow = 360
ActiveWindow.ScrollRow = 350
ActiveWindow.ScrollRow = 343
ActiveWindow.ScrollRow = 340
ActiveWindow.ScrollRow = 330
ActiveWindow.ScrollRow = 319
ActiveWindow.ScrollRow = 313
ActiveWindow.ScrollRow = 306
ActiveWindow.ScrollRow = 299
ActiveWindow.ScrollRow = 289
ActiveWindow.ScrollRow = 282
ActiveWindow.ScrollRow = 275
ActiveWindow.ScrollRow = 269
ActiveWindow.ScrollRow = 258
ActiveWindow.ScrollRow = 255
ActiveWindow.ScrollRow = 248
ActiveWindow.ScrollRow = 241
ActiveWindow.ScrollRow = 238
ActiveWindow.ScrollRow = 235
ActiveWindow.ScrollRow = 228
ActiveWindow.ScrollRow = 225
ActiveWindow.ScrollRow = 218
ActiveWindow.ScrollRow = 214
ActiveWindow.ScrollRow = 211
ActiveWindow.ScrollRow = 204
ActiveWindow.ScrollRow = 201
ActiveWindow.ScrollRow = 197
ActiveWindow.ScrollRow = 191
ActiveWindow.ScrollRow = 180
ActiveWindow.ScrollRow = 174
ActiveWindow.ScrollRow = 167
ActiveWindow.ScrollRow = 160
ActiveWindow.ScrollRow = 157
ActiveWindow.ScrollRow = 150
ActiveWindow.ScrollRow = 143
ActiveWindow.ScrollRow = 136
ActiveWindow.ScrollRow = 130
ActiveWindow.ScrollRow = 126
ActiveWindow.ScrollRow = 120
ActiveWindow.ScrollRow = 106
ActiveWindow.ScrollRow = 99
ActiveWindow.ScrollRow = 92
ActiveWindow.ScrollRow = 86
ActiveWindow.ScrollRow = 79
ActiveWindow.ScrollRow = 76
ActiveWindow.ScrollRow = 69
ActiveWindow.ScrollRow = 62
ActiveWindow.ScrollRow = 55
ActiveWindow.ScrollRow = 52
ActiveWindow.ScrollRow = 48
ActiveWindow.ScrollRow = 38
ActiveWindow.ScrollRow = 31
ActiveWindow.ScrollRow = 28
ActiveWindow.ScrollRow = 25
ActiveWindow.ScrollRow = 18
ActiveWindow.ScrollRow = 15
ActiveWindow.ScrollRow = 11
ActiveWindow.ScrollRow = 8
ActiveWindow.ScrollRow = 4
ActiveWindow.ScrollRow = 1
Range("A1:H2640").Select
Selection.Copy
Sheets("Feuil5").Select
ActiveSheet.Paste
Rows("1:1").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Range("B1:H1").Select
Range("B1:H1").Cut Destination:=Range("A1:G1")
Range("H:H,G:G,E:E,D:D").Select
Range("D1").Activate
Selection.Delete Shift:=xlToLeft
Range("A1:D1").Select
Selection.AutoFilter
Range("C1").Select
Selection.AutoFilter Field:=3, Criteria1:="=H*", Operator:=xlAnd
Range("C1234").Select
Sheets("Feuil4").Select
Range("A1:E1").Select
Selection.Copy
Sheets("Feuil2").Select
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Sheets("Feuil5").Select
Range("A1:D2639").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Feuil2").Select
Range("A2").Select
ActiveSheet.Paste
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Range("A:A,C:C,D:D,E:E").Select
Range("E1").Activate
With Selection
.HorizontalAlignment = xlGeneral
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A1:E70").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
Range("A1").Select
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$1"
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.708661417322835)
.RightMargin = Application.InchesToPoints(0.708661417322835)
.TopMargin = Application.InchesToPoints(0.748031496062992)
.BottomMargin = Application.InchesToPoints(0.748031496062992)
.HeaderMargin = Application.InchesToPoints(0.31496062992126)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
End With
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0)
.BottomMargin = Application.InchesToPoints(0)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
End With
ActiveWindow.SelectedSheets.PrintPreview
End SubVoilât j'espère ne pas avoir fait d'erreur d'incompréhension dans mes questions dans ma macro ou dans le message, si vous voyez une amélioration à apporter dans la macro autre que mes questions n'hésité pas à me le dire je serais ravis d'apprendre.
J'oubliais de vous dire que ma macro fonctionne sur excel 2003
merci d'avance de vos réponses et bonne journée bye
Salut et bienvenue sur le Forum,
Oui, il est possible d’ajouter des SI et des OU dans un code VBA. Et bien d’autres choses très, très intéressantes
Tu as enregistré ton code avec l’enregistreur de macro et ça donne des codes tout à fait imbuvables, tel que celui que tu as mis sur ton fil. L’enregistreur de macro peut être d’une très grande aide, mais il en faut pas en abuser.
Si tu t’intéresses aux macros, tu devrais regarder le ‘Cours VBA’ proposé sur ce site (dans le menu au-dessus de nos messages. Après 10 leçons, tu en sauras déjà énormément.
Pour éviter le défilement d’une macro, place l’instruction ci-dessous en début de code
Application.ScreenUpdating = FalseSinon, rien ne vaut un fichier exemple.
Cordialement.
Merci Yvouille pour ton Aide cela m'a été très utile, désoler de ne pas avoir répondue plutôt, manque de temps.
Je reviendrais sur ce sujet car j'ai encore des modifs à développer, mais il faut que je le prenne le temps.
Encore merci et désoler
A+
Mais je t'en prieArkilius a écrit :Merci Yvouille pour ton Aide cela m'a été très utile
Pas de problème ; alors à dans 3 ou 4 moisArkilius a écrit :Je reviendrais sur ce sujet car j'ai encore des modifs à développer, mais il faut que je le prenne le temps.
Salut