1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
Option Explicit
'permet de récupérer la position en x,y du pointeur de souris
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Type POINTAPI
x As Long
y As Long
End Type
'permet de détecter l'état des touches du clavier
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
'Private Const VK_LCtrl As Long = &HA0 'ici la touche Ctrl de Gauche
Const VK_CONTROL As Long = &H11
Public PositionCursor As POINTAPI, KeyTest As Boolean
Sub demo()
Dim MaPlageDeSableFin As Range, BungalowDeDepart As Range
Dim cellVide As Long
If CtrlKeyState() = True Then 'une touche controle est enfoncée on peu démmarer
KeyTest = CtrlKeyState()
If Not Application.DisplayStatusBar Then Application.DisplayStatusBar = True
Do Until (KeyTest = False)
DoEvents 'redonne la main au system
GetCursorPos PositionCursor 'on recupere la position du curseur en x,y
If BungalowDeDepart Is Nothing Then 'on note la premiere cellule
Set BungalowDeDepart = ActiveWindow.RangeFromPoint(PositionCursor.x, PositionCursor.y)
Else 'on creer la selection depuis la premiere cellule vers la cellule sous le cursseur de souris
Set MaPlageDeSableFin = Range(BungalowDeDepart.Address, ActiveWindow.RangeFromPoint(PositionCursor.x, PositionCursor.y).Address)
MaPlageDeSableFin.Select 'on selectionne la plage
End If
On Local Error Resume Next
cellVide = Application.WorksheetFunction.CountBlank(MaPlageDeSableFin)
Application.StatusBar = "Nbr de cellules vides : " & cellVide
'Range("B1").Value = MaPlageDeSableFin.Cells.Count 'affiche le nombre de cellule de la selection
'Range("B2").Value = MaPlageDeSableFin.Address(False, False) 'affiche l'adresse de la selection
' si la touche Ctrl est relachée on sort de la boucle en changeant l'etat de la variable KeyTest
If CtrlKeyState() = False Then KeyTest = False
Loop
End If
End Sub
Function CtrlKeyState() As Boolean
'permet de détecter si une touches Ctrl est enfoncée
CtrlKeyState = False 'remise a false avant vérif.
If GetKeyState(VK_CONTROL) < 0 Then CtrlKeyState = True
End Function |
Partager