Revenir à la cellule d'origine

  • Initiateur de la discussion Initiateur de la discussion ascal44
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

ascal44

XLDnaute Occasionnel
Bonjour , après l'exécution d'une macro je voudrais revenir à la sélection de la cellule d'où est partie cette macro.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Call form
End Sub

Code:
Sub form() ' format conditionnel de Signalements
Dim lig As Integer, plage As Range

    'Application.ScreenUpdating = False

Application.Calculation = xlManual ' accélère l'exécution
Application.DisplayAlerts = False




For lig = 63 To 163
  With Range(Cells(lig, "A"), Cells(lig, "P"))
    'si la ligne n'est pas vide on l'unit à plage
    If Application.CountA(.Cells) Then _
      Set plage = Union(IIf(plage Is Nothing, .Cells, plage), .Cells)
  End With
 
  Range(Cells(lig, "M"), Cells(lig, "P")).Select 'fusionne MNOP
  Selection.Merge
 

Selection.EntireRow.AutoFit ' hauteur ligne automatique
Selection.EntireRow.RowHeight = Selection.EntireRow.RowHeight + 10 ' + 10 pixel
If Selection.EntireRow.RowHeight < 25 Then Selection.EntireRow.RowHeight = 25 ' hauteur de ligne 25 mini
Next


'efface la MFC et les bordures
With Range("A63:P170")
  .FormatConditions.Delete
  .Borders.LineStyle = xlNone
End With

If plage Is Nothing Then Exit Sub    'si tout est vide...
    
With plage
  
  'crée les bordures
  .Borders.LineStyle = xlContinuous
  '.Interior.ColorIndex = 43
  .HorizontalAlignment = xlLeft 'alignement texte
  .VerticalAlignment = xlCenter
  .Locked = False 'protection cellule
  .FormulaHidden = False
  
  'MFC 1ère condition
  .FormatConditions.Add Type:=xlExpression, Formula1:="=CELLULE(""row"")=LIGNE()"
  With .FormatConditions(1)
    .Font.Bold = True
    .Font.Italic = False
    .Font.ColorIndex = 3
    .Interior.ColorIndex = 6
  End With
  
  'MFC 2ème condition
  .FormatConditions.Add Type:=xlExpression, Formula1:="=MOD(LIGNE();2)=0"
  .FormatConditions(2).Interior.ColorIndex = 15

   'MFC 3ème condition
  .FormatConditions.Add Type:=xlExpression, Formula1:="=MOD(LIGNE();1)=0"
  .FormatConditions(3).Interior.ColorIndex = xlAutomatic
  
 End With
 



     
Application.Calculation = xlAutomatic
Application.DisplayAlerts = True

End Sub

Merci pour votre aide précieuse
 
Re : Revenir à la cellule d'origine

Bonjour à tous,

Pour répondre strictement à ta demande, ascal44, voici un code qui fonctionne :
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim co
    co = ActiveCell.Address
    Call form
    Range(co).Select
End Sub

A+
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
481
Réponses
2
Affichages
461
Réponses
9
Affichages
583
Retour