Application.Intersect
'et
Target.Count > 1
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox "SommeRange(" & Target.Address(0, 0) & ") = " & SommeRange(Target)
End Sub
Private Function SommeRange(Rng As Range) As Double
Dim xrg, xcell, x, somme As Double
If Rng.Count = 1 Then
Set xrg = Rng
Else
Application.EnableEvents = False
On Error Resume Next
Set xrg = Rng.SpecialCells(xlCellTypeVisible)
Application.EnableEvents = True
On Error GoTo 0
End If
For Each xcell In xrg
x = xcell.Value
If x <> "" And IsNumeric(x) And Not IsDate(xcell) Then somme = somme + x
Next xcell
SommeRange = somme
End Function
Bonjour le filJ'ai bien une solution de contournement qui consiste à placer un flag booléen lorsque la sommation est en cours indiquant qu'il faut ignorer l'évènement spontané. Mais j'aimerais avoir une autre option plus déterministe.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
MsgBox "SommeRange(" & Target.Address(0, 0) & ") = " & SommeRange(Target)
Application.EnableEvents = True
End Sub
Franchement, je sais pas quels critères tu as cités pour retrouver ça dans le fatras Excel VBA mais tu as toute mon admiration.En cherchant sur Gogole, le phénomène est connu
J'ai demandé à Gogole: :Franchement, je sais pas quels critères tu as cités pour retrouver ça dans le fatras Excel VBA mais tu as toute mon admiration.
Excel specialcells and Worksheet_SelectionChange event
OK. Bien vu.Excel specialcells and Worksheet_SelectionChange event
Oui c'est ce que @mapomme et @BrunoM45 ont indiqué.la seule solution que je connaisse c'est de bloquer les events
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim adresse, som
som = RangeSomme(Selection, adresse)
MsgBox "Worksheet_SelectionChange Target = " & adresse & vbCrLf & som
End Sub
Function RangeSomme(rng As Range, adresse)
Dim somm#, rng2 As Range
For Each cel In Selection.Columns(1).Cells
If IsNumeric(cel) And Not IsDate(cel) And cel.EntireRow.Hidden = False Then
somm = somm + cel.Value
If rng2 Is Nothing Then Set rng2 = cel Else Set rng2 = Union(rng2, cel)
End If
Next
adresse = rng2.Address
RangeSomme = somm
End Function