G
Greg
Guest
Bonjour,
Le code ci dessous me permet de selectionner la zone de donnée que je souhaite celon un certain critere et de l'imprimer.
Probleme : je dois copier le meme code plusieurs fois pour remedier au fait qu'il peut y avoir plusieurs "zones" de donnée à imprimer celon le critere recherché.
Ma question est donc, comment modifier ce code, par exmple en l'integrant dans une boucle pour qu'il "sanne" toute la feuille excel et m'impirme les donnée que je souhaite.
Encore une autre question : comment interger une gestion des erreurs du style "si rien ne match avec le critere recherché afficher une message box et exit sub" ?
Voilà, j'espere avoir été +/- comprehensible lol
Merci d'avance pour votre aide,
Gregory
/////////////////////////////////////////
Sub Macro1()
'
' Critere de recherche. Par exemple dans ce cas toutes les cellules comme par exmple "342 gregory", "542 georges", etc.
variablefund = "42 g"
' selectionne le debut du fichier
Range("A1").Select
' Commence la recherche
Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
' definis le premier resultat trouvé comme variable pour ne pas qu il le reprenne une deuxieme fois en recommencqnt qu debut
StartCell = ActiveCell.Value
' Selectionne la zone de la cellule trouvée jusqu au mot Totals
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
True)).Select
' Imprime
Selection.PrintOut Copies:=1, Collate:=True
'***
Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
If ActiveCell.Value = StartCell Then
Exit Sub
End If
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
True)).Select
Selection.PrintOut Copies:=1, Collate:=True
'***
Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
If ActiveCell.Value = StartCell Then
Exit Sub
End If
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
True)).Select
Selection.PrintOut Copies:=1, Collate:=True
'***
Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
If ActiveCell.Value = StartCell Then
Exit Sub
End If
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
True)).Select
Selection.PrintOut Copies:=1, Collate:=True
'***
Le code ci dessous me permet de selectionner la zone de donnée que je souhaite celon un certain critere et de l'imprimer.
Probleme : je dois copier le meme code plusieurs fois pour remedier au fait qu'il peut y avoir plusieurs "zones" de donnée à imprimer celon le critere recherché.
Ma question est donc, comment modifier ce code, par exmple en l'integrant dans une boucle pour qu'il "sanne" toute la feuille excel et m'impirme les donnée que je souhaite.
Encore une autre question : comment interger une gestion des erreurs du style "si rien ne match avec le critere recherché afficher une message box et exit sub" ?
Voilà, j'espere avoir été +/- comprehensible lol
Merci d'avance pour votre aide,
Gregory
/////////////////////////////////////////
Sub Macro1()
'
' Critere de recherche. Par exemple dans ce cas toutes les cellules comme par exmple "342 gregory", "542 georges", etc.
variablefund = "42 g"
' selectionne le debut du fichier
Range("A1").Select
' Commence la recherche
Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
' definis le premier resultat trouvé comme variable pour ne pas qu il le reprenne une deuxieme fois en recommencqnt qu debut
StartCell = ActiveCell.Value
' Selectionne la zone de la cellule trouvée jusqu au mot Totals
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
True)).Select
' Imprime
Selection.PrintOut Copies:=1, Collate:=True
'***
Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
If ActiveCell.Value = StartCell Then
Exit Sub
End If
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
True)).Select
Selection.PrintOut Copies:=1, Collate:=True
'***
Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
If ActiveCell.Value = StartCell Then
Exit Sub
End If
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
True)).Select
Selection.PrintOut Copies:=1, Collate:=True
'***
Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
If ActiveCell.Value = StartCell Then
Exit Sub
End If
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
True)).Select
Selection.PrintOut Copies:=1, Collate:=True
'***