Ugrás a tartalomra

Hogyan számolhatjuk az összes kattintást egy adott cellában az Excelben?

Ez a cikk az összes kattintás számlálásáról szól az Excel egy meghatározott cellájában.

Számolja meg az összes kattintást egy VBA kóddal ellátott cellában


Számolja meg az összes kattintást egy VBA kóddal ellátott cellában

Kérjük, tegye a következőket, hogy megszámolja az összes kattintást egy adott cellában az Excelben.

1. A munkalap tartalmazza azt a cellát, amelynek meg kell számlálnia annak összes kattintását, kattintson a jobb gombbal a lap fülére, majd kattintson Kód megtekintése a helyi menüből.

2. Ban,-ben Microsoft Visual Basic for Applications ablakba, kérjük, másolja és illessze be a VBA kód alatt a Kód ablakba.

VBA-kód: Számolja meg az összes kattintást egy adott cellában az Excel-ben

Public xRgS, xRgD As Range
Public xNum As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
    Set xRgS = Range("E2")
    If xRgS Is Nothing Then Exit Sub
    Set xRgD = Range("H2")
    If xRgD Is Nothing Then Exit Sub
    If Intersect(xRgS, Target) Is Nothing Then Exit Sub
    xNum = xNum + 1
    xRgD.Value = xNum
End Sub

Megjegyzések: A kódban az E2 az a cella, amelyre meg kell számolni az összes kattintást, és H2 a számlálás kimeneti cellája. Kérjük, változtassa meg őket szükség szerint.

3. megnyomni a más + Q gombok a Microsoft Visual Basic for Applications ablak.

Mostantól, amikor a megadott munkalapon az E2 cellára kattint, az összes kattintás automatikusan feltöltődik a H2 cellában, az alábbi képernyőkép szerint. Például, ha ötször kattint az E2 cellára, akkor az H5 cellában megjelenik az 5. szám.

A legjobb irodai hatékonyságnövelő eszközök

🤖 Kutools AI Aide: Forradalmasítsa az adatelemzést a következők alapján: Intelligens végrehajtás   |  Kód létrehozása  |  Hozzon létre egyéni képleteket  |  Adatok elemzése és diagramok létrehozása  |  A Kutools funkciók meghívása...
Népszerű szolgáltatások: Ismétlődések keresése, kiemelése vagy azonosítása   |  Üres sorok törlése   |  Oszlopok vagy cellák kombinálása adatvesztés nélkül   |   Kerek Formula nélkül ...
Szuper keresés: Több kritérium VLookup    Többértékű VLookup  |   VLookup több munkalapon   |   Fuzzy Lookup ....
Speciális legördülő lista: Gyors legördülő lista létrehozása   |  Függő legördülő lista   |  Többszörösen válassza ki a legördülő listát ....
Oszlopkezelő: Adjon meg egy adott számú oszlopot  |  Oszlopok mozgatása  |  Kapcsolja be a Rejtett oszlopok láthatósági állapotát  |  Tartományok és oszlopok összehasonlítása ...
Kiemelt funkciók: Rács fókusz   |  Design nézet   |   Nagy Formula bár    Munkafüzet és lapkezelő   |  Erőforrás-könyvtár (Auto szöveg)   |  Dátumválasztó   |  Kombinálja a munkalapokat   |  Cellák titkosítása/dekódolása    E-mailek küldése listánként   |  Szuper szűrő   |   Speciális szűrő (félkövér/dőlt/áthúzott szűrés...) ...
A 15 legjobb eszközkészlet12 szöveg Eszközök (Szöveg hozzáadása, Karakterek eltávolítása,...)   |   50 + Táblázatos Típusai (Gantt-diagram,...)   |   40+ Praktikus képletek (Számolja ki az életkort a születésnap alapján,...)   |   19 beszúrás Eszközök (Helyezze be a QR-kódot, Kép beszúrása az útvonalból,...)   |   12 Átalakítás Eszközök (Számok szavakig, Valuta átváltás,...)   |   7 Egyesítés és felosztás Eszközök (Haladó kombinált sorok, Hasított sejtek,...)   |   ... és több

Töltsd fel Excel-készségeidet a Kutools for Excel segítségével, és tapasztald meg a még soha nem látott hatékonyságot. A Kutools for Excel több mint 300 speciális funkciót kínál a termelékenység fokozásához és az időmegtakarításhoz.  Kattintson ide, hogy megszerezze a leginkább szükséges funkciót...

Leírás


Az Office lap füles felületet hoz az Office-ba, és sokkal könnyebbé teszi a munkáját

  • Füles szerkesztés és olvasás engedélyezése Wordben, Excelben és PowerPointban, Publisher, Access, Visio és Project.
  • Több dokumentum megnyitása és létrehozása ugyanazon ablak új lapjain, mint új ablakokban.
  • 50% -kal növeli a termelékenységet, és naponta több száz kattintással csökkenti az egér kattintását!
Comments (31)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi.
thanks for your amazing code.
as i use this, the counter get restarted every time i open the file,
is there any solution for this issue?
i need to see thclick counts in a larger time window

thanks in advance
This comment was minimized by the moderator on the site
Hi Mehrdad,
I am sorry to reply to you so late. The following code can help solve your problem. Every time you open the file, the counter will start counting from the last counted number.

Public xRgS, xRgD As Range
'Updated by Extendoffice 20230407
Public xNum As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
    Set xRgS = Range("E2")
    If xRgS Is Nothing Then Exit Sub
    Set xRgD = Range("H2")
    If xRgD Is Nothing Then Exit Sub
    If Intersect(xRgS, Target) Is Nothing Then Exit Sub
    xNum = xRgD.Value
    xNum = xNum + 1
    xRgD.Value = xNum
End Sub
This comment was minimized by the moderator on the site
Hola. Muchas gracias por los códigos.
Me gustaría saber cómo contar las veces que se hace clic sobre un enlace en una celda.
Muchas gracias.
This comment was minimized by the moderator on the site
Hi jose maria,
To count the clicks on a hyperlink, you can try the following VBA code.
Suppose hyperlinks are in column A and you want the number of clicks to be populated in the corresponding cell of column B (as shown in the screenshot below)
Please put the following code in the worksheet (code) window.

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
'Updated by Extendoffice 20220805
    Dim Hyperlink As Range
    Set Hyperlink = Target.Range

    Hyperlink.Offset(0, 1) = Hyperlink.Offset(0, 1) + 1
End Sub

https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/clicks_on_a_hyperlink.png
This comment was minimized by the moderator on the site
Bonjour ,
j'aimerai comment je pourrais le nombre de clics sur les cellules D10 à M10 et le retranscrire à la ligne R10 et le faire pour toutes les lignes suivante donc compter les clics sur les cellules D11 à M11 et le transcrire à la ligne R11 etc etc ?

Cordialement
This comment was minimized by the moderator on the site
Hi DUFOUR,
To count the number of clicks from D10 to M10 and output the total number of clicks in R10, you can apply the following VBA code to get it done.
Note: In the code, the range "D10:M30" means that the code only works from the row 10 to row 30, so please specify the rows you want to count.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updated by Extendoffice 20220609
    Dim xNum As Long
    Dim xRgCount, xRg As Range
    
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub

    Set xRg = Range("D10:M30")
    If Intersect(xRg, Target) Is Nothing Then Exit Sub
    Set xRgCount = Range("R" & Target.Row)
    
    If IsNumeric(xRgCount.Value) Then
        xNum = xRgCount.Value + 1
    Else
        xNum = 1
    End If
    xRgCount.Value = xNum
End Sub
This comment was minimized by the moderator on the site
Is there a way to backtrack the number count? For exemple: I'd made 5 clicks, but I just wanted 3. So I change the number in the cell to 3, and when I click again, it continues from 3. OR have the ability to press another cell and decrease the count by 1 if that is easier.
This comment was minimized by the moderator on the site
Hi, thank you for these VBA codes, they almost work for my needs. I fear the fact I need to go past double digits means it will not work. I need to have C8 through to C110 and the corresponding tally count being L8 through to L110. Can you help? Many thanks in advance.
This comment was minimized by the moderator on the site
Hi Andy,The following VBA code can do you a favor. Please have a try.<div data-tag="code">Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xRgS, xRgD As Range
Dim xStrRg As String
Dim xCStr, xVStr As String
Dim xItem As Integer
xCStr = "C8:C110" 'The range of cells you want to record the clicks of each cell
xVStr = "L8:L110" 'The range of cells to place the records in
Set xRgS = Range(xCStr)
Set xRgD = Range(xVStr)
If Not (Intersect(xRgS, Target) Is Nothing) Then
xItem = Target.Row - xRgS.Item(1).Row + 1
xRgD.Item(xItem).Value = xRgD.Item(xItem).Value + 1
End If
End Sub
This comment was minimized by the moderator on the site
Hi, I'm trying to find a way of counting the number of times 20 different cells are being clicked (each one should be counted separately). I came across your VBA code suggestion, tried to adjust it to my specific needs but it won't work. can you please advise how the code should be written? the cells that I would like to count and the cells that the values should appear in are: F12>AU12, F13>AU13, G12>AV12, G13>AV13, H10>AW10, H11>AW11, H12>AW12, H13>AW13, H14>AW14, H15>AW15, I10>AX10, I11>AX11, I12>AX12, I13>AX13, I14>AX14, I15>AX15, J12>AY12, J13>AY13, K12>AZ12, K13>AZ13).
This is the VBA code I've tried with no success:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xRgArray As Variant
Dim xNum
Dim xStrR, xStrS, xStrD As String
Dim xRgS, xRgD As Range

Dim xFNum As Long
xRgArray = Array("F12,AU12", "F13,AU13", "G12,AV12", "G13,AV13", "H10,AW10", "H11,AW11", "H12,AW12", "H13,AW13", "H14,AW14", "H15,AW15", "I10,AX10", "I11,AX11", "I12,AX12", "I13,AX13", "I14,AX14", "I15,AX15", "J12,AY12", "J13,AY13", "K12,AZ12", "K13,AZ13")
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
For xFNum = LBound(xRgArray) To UBound(xRgArray)
xStrR = xRgArray(xFNum)
xStrS = ""
xStrS = Left(xStrR, 2)
xStrD = ""
xStrD = Right(xStrR, 2)
Set xRgS = Nothing
Set xRgS = Range(xStrS)
If TypeName(xRgS) <> "Nothing" Then
Set xRgD = Nothing
Set xRgD = Range(xStrD)
If TypeName(xRgD) <> "Nothing" Then
If TypeName(Intersect(xRgS, Target)) <> "Nothing" Then
xRgD.Value = xRgD.Value + 1
End If
End If
End If
Next
End Sub

Thank you in advance, for your help.
This comment was minimized by the moderator on the site
Hi,The below code can help. Please have a try. Thank you.<div data-tag="code">Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xRgS, xRgD As Range
Dim xStrRg As String
Dim xFNum As Integer
Dim xArr1, xArr2
If Target.Cells.Count > 1 Then Exit Sub
xStrRg = "F12-AU12; F13-AU13; G12-AV12; G13-AV13; H10-AW10; H11-AW11; H12-AW12; H13-AW13; H14-AW14; H15-AW15; I10-AX10; I11-AX11; I12-AX12; I13-AX13; I14-AX14; I15-AX15; J12-AY12; J13-AY13; K12-AZ12; K13-AZ13"
On Error Resume Next
xArr1 = Split(xStrRg, ";")
For xFNum = 0 To UBound(xArr1)
xArr2 = Split(xArr1(xFNum), "-")
Set xRgS = Range(xArr2(0))
Set xRgD = Range(xArr2(1))
If Not (Intersect(xRgS, Target) Is Nothing) Then
xRgD.Value = xRgD.Value + 1
End If
Next
End Sub
This comment was minimized by the moderator on the site
Crystal, The Above code is great for the sheet I am working with, thank you. But I have a question about adding a time macro so that everyday (excluding weekends) the tally moves to the next row in the sheet for example:

Row 3 - 7/1/2021 "B1-B3; C1-C3; D1-D3"
Row 4 - 7/2/2021 "B1-B4; C1-C4; D1-D4"
Row 5 - 7/3/2021 "B1-B5; C1-C5; D1-D5"

If this is possible? thx, Ken
This comment was minimized by the moderator on the site
The Above corrected code is great for the sheet I am working with, thank you. But I have a question about adding a time macro so that everyday (excluding weekends) the tally moves to the next row in the sheet for example:
Row 3 - 7/1/2021 "B1-B3; C1-C3; D1-D3"Row 4 - 7/2/2021 "B1-B4; C1-C4; D1-D4"Row 5 - 7/3/2021 "B1-B5; C1-C5; D1-D5"
This comment was minimized by the moderator on the site
Como zerar a contagem? How to reset the score?
This comment was minimized by the moderator on the site
Hi,
If you want to reset the counter, please add the below VBA code at the end of the original code which has been provided above, and then run it.

Sub ClearCount()
xRgD.Value = ""
xNum = 0
End Sub
This comment was minimized by the moderator on the site
Can you provide a code that allows counting clicks from A2, B2 cells through A14, B14 cells. Thanks in advance.
This comment was minimized by the moderator on the site
Hi Barbara,
Do you mean counting the total clicks in range A2:B14? Or clicks for each cell in range A2:B14?
This comment was minimized by the moderator on the site
Hola
Hay alguna manera de programar el conteo de clicks de acuerdo a la fecha, es decir programar varias celdas para que cuenten con la fecha del día?
This comment was minimized by the moderator on the site
Hello, there is a way to back the counting for any number that I want? For exemple: I'd made 5 clicks, but i just wanted 3. So I change the number in the cell to 3, and when I click again, it continue from 3.
Thank for the code!
This comment was minimized by the moderator on the site
Hi,
Sorry can’t help you with this, welcome to post any question about Excel to our forum: https://www.extendoffice.com/forum.html. You will get more Excel supports from our professional or other Excel fans.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations